here is only basic implementation of problems for beginners. If you have any problem with any solution or any basic concept of programming or you want more efficient solution you can mail me.
my suggestion is not to copy and paste codes from here try to understand the logic and think why you were not able to solve it.

Tuesday, 30 December 2014

Rivals

problam statement is here


#include<stdio.h>
#define MOD 1000000007

long long ar[2000010];
void fact(){
long long i;
    ar[0]=1;
    ar[1]=1;
    for(i=2;i<=2000000;i++)
        ar[i]=(ar[i-1]*i)%MOD;
}
long long fermet(long long x){
    long long a=1,p=x,n=MOD-2;
    while(n){
        if(n&1)
            a=(a*p)%MOD;
        p=(p*p)%MOD;
        n>>=1;
    }
    return a;
}
int main(){
    int t,a,b;
    long long c,d;
    fact() ;
    scanf("%d",&t);
    while(t--){
        scanf("%d %d",&a,&b);
        c=(fermet(ar[a])*fermet(ar[b]))%MOD;
        d=(ar[a+b]*c)%MOD;
        printf("%lld\n",d);
    }
    return 0;
}

No comments:

Post a Comment