您的位置:首页 > 大数据 > 人工智能

2015 Multi-University Training Contest 10 hdu 5407 CRB and Candies

2015-08-22 10:03 411 查看

CRB and Candies

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 453 Accepted Submission(s): 222


[align=left]Problem Description[/align]
[align=left] [/align]

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 \leq K \leq 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 \leq T \leq 300$
$1 \leq N \leq 10^6$

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

Author
KUT(DPRK)

解题:看 crazyacking 的解释,涨姿势了

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1000002;
const int mod = 1000000007;
bool np[maxn] = {true,true};
int p[maxn],tot;
void init(){
for(int i = 2; i < maxn; ++i){
if(!np[i]) p[tot++] = i;
for(int j = 0; j < tot && i*p[j] < maxn; ++j){
np[i*p[j]] = true;
if(i%p[j] == 0) break;
}
}
}
int main(){
init();
int kase,n;
scanf("%d",&kase);
while(kase--){
scanf("%d",&n);
LL ret = 1;
for(int i = 0; i < tot; ++i){
for(LL j = p[i]; j <= n; j *= p[i])
if((n+1)%j) ret = ret*p[i]%mod;
}
printf("%I64d\n",ret);
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: