标签:crb and candies hdu5407 2015 multi-universit lcm gcd
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 358 Accepted Submission(s): 160
5 1 2 3 4 5
1 2 3 12 10
解题:
转载请注明出处:寻找&星空の孩子
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5407
//lcm(C(n,0),C(n,1),C(n,2),,,,C(n,n))=lcm(1,2,,,,n,n+1)/(n+1) //乘法逆元!(除法+取模) //f(1)=1 //if n=p^k then f(n)=f(n-1)*p else f(n) =f(n-1) #include<stdio.h> #include<string.h> #define mod 1000000007 #define LL __int64 const LL maxv=1e6+5; bool isnp[maxv]={false}; LL prime[maxv],pnum;//素数数组,素数个数 LL cas,f[maxv]={0}; void get_prime()//素数打表 { pnum=0; LL i,j; // memset(isnp,0,sizeof(isnp)); isnp[0]=isnp[1]=true; for(i=2; i<maxv; i++) { if(!isnp[i]){prime[pnum]=i;pnum++;} for(j=0; j<pnum&&prime[j]*i<maxv; j++) { isnp[i*prime[j]]=true; if(i%prime[j]==0)break; } } for(i=0;i<pnum;i++) { for(j=prime[i];j<maxv;j*=prime[i]) { f[j]=prime[i]; } } } void init() { get_prime(); f[1]=1; for(LL i=2;i<maxv;i++) { if(f[i]) f[i]=f[i]*f[i-1]%mod; else f[i]=f[i-1]; } // for(LL i=2;i<100;i++) // { // printf("i=%I64d\t f=%I64d\n",i,f[i]); // if(i%10==0)printf("\n"); // } } void exgcd(LL a,LL b,LL &d,LL &x,LL &y) { if(!b){d=a;x=1;y=0;} else { exgcd(b,a%b,d,y,x); y-=x*(a/b); } } int main() { int T; LL n; init(); scanf("%d",&T); while(T--) { scanf("%I64d",&n); LL x,y,d; exgcd(n+1,mod,d,x,y);//ax = 1 (mod m) if(d==1){x=(x%mod+mod)%mod;} printf("%I64d\n",f[n+1]*x%mod); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
CRB and Candies(lcm(C(n,0)..C(n,n)=lcm(1,2,,,n+1)/(n+1)))hdu5407
标签:crb and candies hdu5407 2015 multi-universit lcm gcd
原文地址:http://blog.csdn.net/u010579068/article/details/47833525