2015 Multi-University Training Contest 10 hdu 5407 CRB and Candies
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
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 的解释,涨姿势了
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 const int maxn = 1000002; 5 const int mod = 1000000007; 6 bool np[maxn] = {true,true}; 7 int p[maxn],tot; 8 void init(){ 9 for(int i = 2; i < maxn; ++i){ 10 if(!np[i]) p[tot++] = i; 11 for(int j = 0; j < tot && i*p[j] < maxn; ++j){ 12 np[i*p[j]] = true; 13 if(i%p[j] == 0) break; 14 } 15 } 16 } 17 int main(){ 18 init(); 19 int kase,n; 20 scanf("%d",&kase); 21 while(kase--){ 22 scanf("%d",&n); 23 LL ret = 1; 24 for(int i = 0; i < tot; ++i){ 25 for(LL j = p[i]; j <= n; j *= p[i]) 26 if((n+1)%j) ret = ret*p[i]%mod; 27 } 28 printf("%I64d\n",ret); 29 } 30 return 0; 31 }