CRB and Candies(lcm(C(n,0)..C(n,n)=lcm(1,2,,,n+1)/(n+1)))hdu5407
来源:互联网 发布:快递数据接口 编辑:程序博客网 时间:2024/06/05 21:15
CRB and Candies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 358 Accepted Submission(s): 160
Problem Description
CRB has N different candies. He is going to eat K candies.
He wonders how many combinations he can select.
Can you answer his question for allK (0 ≤ K ≤ N )?
CRB is too hungry to check all of your answers one by one, so he only asks least common multiple(LCM) of all answers.
He wonders how many combinations he can select.
Can you answer his question for all
CRB is too hungry to check all of your answers one by one, so he only asks least common multiple(LCM) of all answers.
Input
There are multiple test cases. The first line of input contains an integer T , indicating the number of test cases. For each test case there is one line containing a single integer N .
1 ≤T ≤ 300
1 ≤N ≤ 10^6
1 ≤
1 ≤
Output
For each test case, output a single integer – LCM modulo 1000000007(10^9+7 ).
Sample Input
512345
Sample Output
1231210
Author
KUT(DPRK)
Source
2015 Multi-University Training Contest 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 __int64const 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;}
0 0
- CRB and Candies(lcm(C(n,0)..C(n,n)=lcm(1,2,,,n+1)/(n+1)))hdu5407
- HDOJ 5407 CRB and Candies(求1到n的LCM 位图储存结构)
- LCM from 1 to n
- LCM from 1 to n
- Codeforces Round #157 (Div. 1), problem: (C) Little Elephant and LCM DP+组合数学 0(n^(5/2))
- lightoj 1289 LCM from 1 to n
- LightOJ 1289 LCM from 1 to n
- LightOJ 1289 LCM from 1 to n
- LightOJ 1289 LCM from 1 to n
- n&n-1 n&-n
- n&-n n&n-1
- LightOJ 1245 求(n/1+n/2+...+n/n)
- 要过程 n)...+1/(n+1)C(n 1+1/2C(1 n)=
- Light OJ 1289 LCM from 1 to n(lcm问题+内存优化)
- C(n,m)=C(n-1,m-1)+C(n-1,m)
- ZOJ 3175 Number of Containers(n/1+n/2+...+n/(n-1)+n/n求法)
- 【 51NOD 1434 素数筛 】【数论+思维+筛素数】区间LCM【找到一个最小整数M,满足M>N,LCM(N+1,N+2,..,M-1,M)是LCM(1,2,3,4,.,N-1,N) 的倍数】
- n&(n-1)n-1 应用
- Android国内资源下载
- capture screen
- Android DrawerLayout 高仿QQ5.2双向侧滑菜单
- POJ 3258 River Hopscotch (二分,最大化最小值)
- Android.mk
- CRB and Candies(lcm(C(n,0)..C(n,n)=lcm(1,2,,,n+1)/(n+1)))hdu5407
- Maven + Spring hello world example
- 如何通过PS把LOGO的背景色变透明
- Qt-提升界面程序的可读性
- UVA 401 Palindromes
- UFLDL教程(一)---稀疏自编码器
- ViewPager滑动监听
- springmvc项目jsp页面传递参数至controller中文乱码解决方案
- Linux时间子系统之(二):软件架构