UVA- 374 (Big Mod) Recursive Modular Exponentiation







 At first check it :  Big Mod Tutorial in Bangla


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
long long int bigmod(long long int x,long long int n,long long int m)
{
    long long  int y;
    if(n==0)
    {
        return 1;
    }
    else if(n%2==0)
    {
        y=bigmod(x,n/2,m);
        return ((y*y)%m);
    }
    else
    {
        return(((x%m)*bigmod(x,n-1,m))%m);
    }
}
int main()
{
    long long int x,n,m;
    while(cin>>x>>n>>m)
    {
    cout<<bigmod(x,n,m)<<endl;
    }
    return 0;

}
Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment