#include<bits/stdc++.h>
using namespace std;
int big_mod(long long int a,long long int p,long long int m)
{
if(p==0) return 1%m;
int x = big_mod(a,p/2,m);
x = (x*x)%m;
if(p%2==1)
{
x=(x*a)%m;
}
return x;
}
int main()
{
long long int a,p,m;
cout<<"Enter 1st Number: "<<endl;
cin>>a;
cout<<"Enter the Power: "<<endl;
cin>>p;
cout<<"Enter the Mod Value: "<<endl;
cin>>m;
int value = big_mod(a,p,m);
cout<<"Your Ans: "<<value<<endl;
return 0;
}
Output
Enter 1st Number:
3
Enter the Power:
3
Enter the Mod Value:
5
Your Ans:
2
Add your comment