【BZOJ4403】序列统计【Lucas定理】

【题目链接】

【CodeChef-CSEQ的题解】

/* Telekinetic Forest Guard */
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef unsigned long long ULL;

const int maxn = 1000505;
const ULL p = 1000003;

ULL fact[maxn];

inline int iread() {
	int f = 1, x = 0; char ch = getchar();
	for(; ch < '0' || ch > '9'; ch = getchar()) f = ch == '-' ? -1 : 1;
	for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	return f * x;
}

inline ULL qpow(ULL x, ULL n) {
	ULL res = 1;
	for(ULL t = x; n; n >>= 1, t = t * t % p) if(n & 1) res = res * t % p;
	return res;
}

inline ULL inv(ULL x) {
	return qpow(x, p - 2);
}

inline ULL bf(ULL n, ULL m) {
	if(n < m) return 0;
	return fact[n] * inv(fact[m]) % p * inv(fact[n - m]) % p;
}

inline ULL C(ULL n, ULL m) {
	ULL res = 1;
	for(ULL nn = n / p, mm = m / p; n && m && res; n = nn, m = mm, nn /= p, mm /= p)
		(res *= bf(n - nn * p, m - mm * p)) %= p;
	return res;
}

int main() {
	fact[0] = 1;
	for(int i = 1; i <= 1000005; i++) (fact[i] = fact[i - 1] * i) %= p;

	ULL n, L, R;
	for(int T = iread(); T; T--) {
		n = iread(); L = iread(); R = iread();
		printf("%llu\n", (C(n + R - L + 1, n) - 1 + p) % p);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值