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;

}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

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. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment