let's start Code

DCP-23: Another Bigmod Problem

DCP-23: Another Bigmod Problem

Topic: BigMod

solution:


/// https://www.devskill.com/CodingProblems/ViewProblem/23
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline ll modMul(ll a, ll b, ll MOD)
{
ll r = 0;
a %= MOD;
while(b)
{
if(b%2) r = (r +a)%MOD;
a = (a+a)%MOD;
b/=2;
}
return r;
}
inline ll modPow(ll b, ll p, ll MOD)
{
ll r = 1;
while(p)
{
if(p%2) r = modMul(r, b, MOD);
b = modMul(b, b, MOD);
p/=2;
}
return r;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll a,b,c;
int t,i=0;
cin >> t;
while(t--)
{
i++;
cin>>a>>b>>c;
cout<<"Case "<<i<<": ";
cout<<modPow(a,b,c)<<endl;
}
return 0;
}
view raw BigMod.cpp hosted with ❤ by GitHub
Share:

Related Posts:

No comments:

Post a Comment

About

let's start CODE

Popular Posts