Description
Input
Output
For each testcase,output an integer,denotes the number you will tell Mr. Mindless
Sample Input
3 2 4 4 3 5
Sample Output
1 4
讀懂題意,這題就是一道快速冪的問題。直接上模板,水題。
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <string>
#include <string.h>
#include <queue>
#include <set>
using namespace std;
#define ll long long
const int maxn=305;
ll n,m,C;
ll quickmod(ll a,ll b,ll m)
{
ll ans=1;
while(b)
{
if(b&1)
{
ans=(ans%m*a)%m;
b--;
}
b/=2;
a=a%m*a%m;
}
return ans%m;
}
int main()
{
while(cin>>n>>m>>C)
{
cout<<quickmod(n,m,C)<<endl;
}
return 0;
}
/**********************************************************************
Problem: 1162
User: jk1601zr
Language: C++
Result: AC
Time:36 ms
Memory:2020 kb
**********************************************************************/