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;
}
0 comments:
Post a Comment