hdu-5407(多校2015)
2015-08-20 21:03
357 查看
CRB and Candies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 193 Accepted Submission(s): 73
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 all K(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.
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 ≤ 106
Output
For each test case, output a single integer – LCM modulo 1000000007(109+7).
Sample Input
5 1 2 3 4 5
Sample Output
1 2 3 12 10
题意:求g(n)。数学不好,谁告诉我这哪来
求g(n),先通过构造f(n)=lcm(1,2,....n),然后求g(n);
//#pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<stdio.h> #include<math.h> #include <string> #include<string.h> #include<map> #include<queue> #include<set> #include<utility> #include<vector> #include<algorithm> #include<stdlib.h> using namespace std; #define eps 1e-8 #define inf 0x3f3f3f3f #define rd(x) scanf("%d",&x) #define rd2(x,y) scanf("%d%d",&x,&y) #define ll long long int #define mod 1000000007 #define maxn 1000005 #define maxm 100005 int prime[maxn],pn; int v[maxn]; ll f[maxn],g[maxn]; void init_prime() { int i, j; for(i = 2;i <= sqrt(maxn); ++i) { if(!prime[i]) for(j = i * i; j < maxn; j += i) prime[j] = 1; } pn = 0; for(i = 2;i <= maxn; ++i) if(!prime[i]) prime[pn++] = i; } ll inv(ll a,ll m){// (x/a)%m的逆元 ll p=1,q=0,b=m,c,d; while(b>0){ c=a/b; d=a; a=b; b=d%b; d=p; p=q; q=d-c*q; } return p<0?p+m:p; } int main() { int t; rd(t); memset(v,0,sizeof(v)); init_prime(); for(int i=0;i<pn;i++) { ll k=prime[i]; while(k<maxn){ v[k]=prime[i]; k*=prime[i]; } } f[1]=1; for(int i=2;i<maxn;i++){ if(v[i]) { f[i]=f[i-1]*v[i]; f[i]%=mod; } else f[i]=f[i-1]; f[i]%=mod; g[i-1]=f[i]*inv(i,mod); g[i-1]%=mod; } int n; while(t--){ rd(n); printf("%I64d\n",g ); } return 0; }
相关文章推荐
- 博客贴自定义高亮代码
- hdu5407数学
- CRB and String(HDUOJ--5414
- mapreduce查询mysql表中记录数
- Perfection
- 2015年8月20日21:03:18 firstNotRepeatingChar 哈希表实现O(n)
- 手工释放linux内存――/proc/sys/vm/drop_cache
- Hibernate 所有缓存机制详解
- 第90讲:基于Scala的Actor之上的分布式并发消息驱动框架Akka初体验学习笔记
- android 添加视频、图片、录音上传(二)
- [HDOJ4911]Inversion
- 电脑反应慢的原因
- NYOJ 709 异 形 卵(区域最大值,水题)
- [Linux]工作中常见的命令
- Win10下安装Genymotion出现virtualization engine not found的解决方案
- HDOJ 1241 Oil Deposits (DFS)
- C++那些细节--函数的默认参数
- poj 2406 Power Strings(kmp求一个串的重复子串)
- C语言中do...while(0)的妙用-避免goto
- OJ刷题---奇怪的分式