HDU 5407(CRB and Candies-OEIS)

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


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.
 

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
 

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
 

Recommend
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;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值