首页 > 其他 > 详细

bzoj4403: 序列统计

时间:2016-01-21 19:06:17      阅读:659      评论:0      收藏:0      [点我收藏+]

我们很容易发现答案是C(R-L+N+1,N)-1

然后用一下lucas定理就行了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#define ll long long
#define P 1000003

using namespace std;
int pow2(int x,int y){
	int ret=1;
	while (y){
		if (y&1) ret=(ll)ret*x%P;
		x=(ll)x*x%P;
		y=y>>1; 
	}
	return ret;
}

int fact[P+233];
int c(int n,int m){
	if (n<m) return 0;
	return (ll)fact[n]*pow2(fact[m],P-2)%P*pow2(fact[n-m],P-2)%P;
}
int lucas(int n,int m){
	int ret=1;
	for (;n||m;n/=P,m/=P) ret=(ll)ret*c(n%P,m%P)%P;
	return ret;
}


int main(){
	for (int i=fact[0]=1;i<=P;++i) fact[i]=(ll)fact[i-1]*i%P;
	int testnumber;scanf("%d",&testnumber);
	while (testnumber--){
		int n,l,r;
		scanf("%d%d%d",&n,&l,&r);
		printf("%d\n",(lucas(r-l+n+1,n)+P-1)%P);
	}
	return 0;
}

  

bzoj4403: 序列统计

原文:http://www.cnblogs.com/wangyurzee7/p/5148769.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!