Esempio n. 1
0
int main(){
    scanf("%s %s %d",b,n,&c);
    
    int b_mod_c = big_mod(b,c);
    big_minus_1(n);
    int b_n_mod_c = exp_big_mod(b_mod_c,n,c);
    big_minus_1(b);
    int b_1_mod_c  = big_mod(b,c);
    int ans=((long long)b_1_mod_c *b_n_mod_c ) %c ;
    printf("%d\n",ans==0?c:ans);
    return 0;
}
Esempio n. 2
0
long long int big_mod(int B, int P, int M) {
    if ( !P ) return 1;
    if ( P == 1 ) {
        return B;
    } else {
        if ( P % 2  == 0 ) {
            return ( big_mod( B  , P / 2 , M)  *  big_mod( B  , P / 2 , M) ) % M;  
        }  else {
            return ( big_mod( B  , P - 1 , M)  *  big_mod( B  , 1 , M) ) % M;  
        }
    }
    
}
int main(){

    int i,j,k,l,test,t=1,n;

    //freopen("in.txt","r",stdin);

    scanf("%d",&test);

    while(test--){

        scanf("%d %d",&n,&k);

        double ans=cal1(n,k);
        double v=1000;
        if(ans<v) ans=ans*v;
        ii ans1=ans;
        while(ans1>=1000) ans1/=10;
        printf("Case %d: %03lld",t++,ans1);
        printf(" %03lld\n",big_mod(n,k,1000));


    }

    return 0;
}
Esempio n. 4
0
static void big_mulmod (u32 *num1, u32 *num2, u32 *mod)
{
	u32 lnum[128];
	int len = mod[63] ? 64 : 32;

	big_mul (len, lnum, num1, num2);
	big_mod (len, num1, lnum, mod);
}
Esempio n. 5
0
void EncryptionType1::big_mulmod (u32 *num1, u32 *num2, u32 *mod)
{
	u32 lnum[128];
	int len = mod[63] ? 64 : 32;

	big_mul (len, lnum, num1, num2);
	big_mod (len, num1, lnum, mod);
}
Esempio n. 6
0
int main(int argc, const char *argv[])
{
    int b,p,m;
    long long int t;
    while ( scanf("%d %d %d", &b, &p ,&m ) != EOF ) {
        printf("%lld", big_mod(b,p,m));
    }
    return 0;
}
ii big_mod(ii b,ii p,ii m){

    if(p==0) return 1;
    if(p==1) return b%m;

    ii ret;
    ret=big_mod(b,p/2,m);
    ret*=ret; ret%=m;
    if(p%2) ret*=b;
    ret%=m;
    return ret;

}