Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef vector<int> vi;
- #define rapid_io() ios::sync_with_stdio(false);cin.tie(0);
- #define endl '\n'
- #define pb push_back
- #define all(a) (a).begin(),(a).end()
- #define rall(a) (a).rbegin(),(a).rend()
- ll recursive(ll b,ll p,ll m)
- {
- if(p==0)
- return 1;
- else if(p%2==0)
- {
- return recursive(((b*b)%m),p/2,m);
- }
- else
- {
- return (b*recursive((b*b)%m,(p-1)/2,m)%m);
- }
- }
- int main()
- {
- rapid_io();
- ll b,p,m;
- while(cin>>b>>p>>m){
- cout<<recursive(b,p,m)<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement