您的位置:首页 > 其它

HDU 5407(CRB and Candies-OEIS)

2015-08-30 19:50 471 查看

CRB and Candies

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 646 Accepted Submission(s): 321



[align=left]Problem Description[/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
≤ 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.

[align=left]Input[/align]
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

[align=left]Output[/align]
For each test case, output a single integer – LCM modulo 1000000007(109+7).

[align=left]Sample Input[/align]

5
1
2
3
4
5


[align=left]Sample Output[/align]

1
2
3
12
10


[align=left]Author[/align]
KUT(DPRK)

[align=left]Source[/align]
2015 Multi-University Training Contest 10

[align=left]Recommend[/align]
wange2014 | We have carefully selected several similar problems for you: 5426 5425 5424 5423 5422

在OEIS上,查出答案=lcm(1,2,..,n)/n

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (1000000007)
#define MAXN (1000000+10)
typedef long long ll;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
ll gcd(ll a,ll b) {
if (b==0) return a;return gcd(b,a%b);
}
ll lcm(ll a,ll b){
return a/gcd(a,b)*b;
}
int n;

int p[MAXN],tot=0;
bool b[MAXN]={0};
void make_prime()
{
int n=1000005;
Fork(i,2,n) {
if (!b[i]) b[i]=1,p[++tot]=i;

For(j,tot) {
if (p[j]*i>n) break;
b[p[j]*i]=1;
if (i%p[j]==0) break;
}
}

}

ll pow2(ll a,ll b){
if (b==0) return 1;
if (b==1) return a;
ll t=pow2(a,b/2);
t=t*t%F;
if (b&1) t=t*a%F;
return t;
}

int main()
{
//	freopen("B.in","r",stdin);

make_prime();
//	For(i,100) cout<<p[i]<<' ';

int T; cin>>T;
while(T--) {
cin>>n; ++n;
ll ans=1;

ll c=1;
//	For(i,n/2) c=c*(n-i+1)/i,ans=lcm(ans,c),cout<<c<<endl;

For(i,tot) {
if (p[i]>n) break;

double k=log(n)/log(p[i]);
int k2=(int)k;

ans=mul(ans,pow2(p[i],k2));

}
ans=mul(ans,pow2(n,F-2));

cout<<ans<<endl;
}

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