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 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.
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
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
Author
KUT(DPRK)
Source
居然可以找到规律呢!!我们算是懵了,没想过找规律的。哭哭哭~~~
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
#define ll long long
ll mod = 1000000007;
#define maxn 1000007
int 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;
}