hdu 5407 CRB and Candies 2015多校联合训练赛#10 找规律 素数筛法

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.
 

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
 


居然可以找到规律呢!!我们算是懵了,没想过找规律的。哭哭哭~~~



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
















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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GDRetop

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值