CRB and Candies (LCM (C (n,0): C (n,n) =LCM (,,, n+1)/(n+1)) hdu5407

Source: Internet
Author: User

CRB and Candies

Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 358 Accepted Submission (s): 160


problem DescriptionCRB has  N  Different candies. He is going to eat  K  Candies.
He wonders how many combinations he can select.
Can you answer he question for all  K (0≤  K  ≤  N )?
CRB is too hungry to check all the your answers one by one, so he only asks least common multiple (LCM) of all answers.


Input

There is multiple test cases. The first line of input contains an integer  T , indicating the number of test cases. For all test case there are one line containing a single integer  N .
1≤  T  ≤300
1≤  N  ≤  10^ 6


Output

For each test case, output a single INTEGER–LCM modulo 1000000007 ( 10^9+7 ).


Sample Input

512345


Sample Output

1231210


Author

KUT (DPRK)


Source

Multi-university Training Contest 10


Solving:

Reprint Please specify the Source: Looking for Children & stars   

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5407

LCM (c (n,0), C (n,1), C (n,2),,,, C (n,n)) =LCM (,,,, n,n+1)/(n+1)//multiplication Inverse! (Division + Modulo)//f (1) =1//if n=p^k then f (n) =f (n-1) *p else f (n) =f (n-1) #include <stdio.h> #include <string.h> #define MoD 1000000007#define ll __int64const ll Maxv=1e6+5;bool Isnp[maxv]={false};    ll prime[maxv],pnum;//Prime Array, number of elements ll cas,f[maxv]={0};void get_prime ()//prime table {pnum=0; LL i,j;    memset (isnp,0,sizeof (ISNP));    Isnp[0]=isnp[1]=true;        for (i=2; i<maxv; i++) {if (!isnp[i]) {prime[pnum]=i;pnum++;}            for (j=0; j<pnum&&prime[j]*i<maxv; J + +) {isnp[i*prime[j]]=true;        if (i%prime[j]==0) break;        }} for (i=0;i<pnum;i++) {for (J=prime[i];j<maxv;j*=prime[i]) {f[j]=prime[i];    }}}void init () {get_prime ();    F[1]=1;        for (LL i=2;i<maxv;i++) {if (f[i]) f[i]=f[i]*f[i-1]%mod;    else f[i]=f[i-1];   }//for (LL i=2;i<100;i++)//{//printf ("I=%i64d\t f=%i64d\n", i,f[i]);//     if (i%10==0) printf ("\ n"),//}}void EXGCD (LL a,ll b,ll &d,ll &x,ll &y) {if (!b) {d=a;x=1;y=0;}        else {EXGCD (b,a%b,d,y,x);    Y-=x* (A/b);    }}int Main () {int T;    LL N;    Init ();    scanf ("%d", &t);        while (t--) {scanf ("%i64d", &n);        LL x,y,d;        EXGCD (n+1,mod,d,x,y);//ax = 1 (mod m) if (d==1) {x= (x%mod+mod)%mod;}    printf ("%i64d\n", f[n+1]*x%mod); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

CRB and Candies (LCM (C (n,0): C (n,n) =LCM (,,, n+1)/(n+1)) hdu5407

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.