hdu 5407 CRB and Candies 2015多校聯合訓練賽#10 找規律 素數篩法

來源:互聯網
上載者:User

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 2015 Multi-University Training Contest 10  


居然可以找到規律呢。。我們算是懵了,沒想過找規律的。哭哭哭~~~



#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>using namespace std;#define ll long longll mod = 1000000007;#define maxn 1000007int 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;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.