hdu 5407 CRB and Candies 2015多校联合训练赛#10 找规律 素数筛法
来源:互联网 发布:qq飞车鸿黎耀世数据 编辑:程序博客网 时间:2024/06/06 12:52
CRB and Candies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 402 Accepted Submission(s): 185
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 ≤ 106
1 ≤
1 ≤
Output
For each test case, output a single integer – LCM modulo 1000000007(109+7 ).
Sample Input
512345
Sample Output
1231210
Author
KUT(DPRK)
Source
2015 Multi-University Training Contest 10
居然可以找到规律呢!!我们算是懵了,没想过找规律的。哭哭哭~~~
#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>using namespace std;#define ll long longll mod = 1000000007;#define maxn 1000007int check[maxn];ll LCM[maxn],ni[maxn];ll cal(ll a,int b){ ll ans = 1; while(b){ if(b&1) ans = ans*a%mod; b /= 2; a = a*a%mod; } return ans;}void init(){ memset(check,0,sizeof(check)); for(int i = 2;i < maxn; i++){ if(check[i] == 0){ for(int j = i;j < maxn; j+=i) check[j] = 1; for(ll j = i;j < maxn; j = j*i) check[j] = i; } } LCM[1] = 1; for(int i = 2;i < maxn; i++){ LCM[i] = LCM[i-1]*check[i]%mod; } for(int i = 1; i < maxn; i++) ni[i] = cal(i,mod-2);}int main(){ init(); int t,n; scanf("%d",&t); while(t--){ scanf("%d",&n); ll ans = LCM[n+1]*ni[n+1]%mod; printf("%I64d\n",ans); } return 0;}
0 0
- hdu 5407 CRB and Candies 2015多校联合训练赛#10 找规律 素数筛法
- hdu 5411 CRB and Puzzle 2015 多校联合训练赛#10 快速矩阵幂
- hdu 5414 CRB and String 2015多校联合训练赛#10 贪心
- hdu 5410 CRB and His Birthday 2015多校联合训练赛#10 dp 动态规划
- hdu 5416 CRB and Tree 2015多校联合训练赛#10 枚举
- hdu 5409 CRB and Graph 2015多校联合训练赛#10 dfs
- hdu 5406 CRB and Apple, 2015多校联合训练赛,费用流
- HDU 5407 CRB and Candies(数学 素数表+预处理+快速幂+乘法逆元)——多校练习10
- hdu 5412 CRB and Queries 2015多校联合训练赛#10 分治 求区间第k大数
- hdu 5407CRB and Candies
- HDU 5407 CRB and Candies
- hdu 5407 CRB and Candies
- hdu 5407 CRB and Candies
- hdu 5407 CRB and Candies(素数筛选法,除法取模(乘法逆元))
- HDU 5407 CRB and Candies(素数筛 + 逆元 + 组合数公式)——2015 Multi-University Training Contest 10
- HDU 5407 CRB and Candies (Kummer定理)
- hdu 5407 CRB and Candies(数论)
- HDU 5407(CRB and Candies-OEIS)
- 文件读写操作笔记
- HTML 笔记 ---Day01
- 从SASI到SAS:SCSI走过25年
- Fastboot线刷“复活”之刷机心得(三)——错误处理
- java获取文件md5值
- hdu 5407 CRB and Candies 2015多校联合训练赛#10 找规律 素数筛法
- Mysql删除多表及多表记录sql语句
- wenti
- tomcat 虚拟目录配置
- 【DP】 HDOJ 5406 CRB and Apple
- thinkphp 类库扩展
- 修改WampServer的默认端口
- 图片翻转效果的实现
- C语言的static和extern关键字的使用