题意】
求a^b mod c,a,b,c都是整数。
【输入格式】
一行三个整数 a、b、c。 1 ≤ a,b,c ≤ 10^9
【输出格式】
求a^b mod c,a,b,c都是整数。
【输入格式】
一行三个整数 a、b、c。 1 ≤ a,b,c ≤ 10^9
【输出格式】
一行,a^b mod c的值。
#include<cstdio>
using namespace std;
long long a,b,c;
long long doit(long long x)
{
if (x==1) return a%c;
else
{
long long wyxshuaibi=doit(x/2);
if (x%2==0) return wyxshuaibi*wyxshuaibi%c;
else return a%c*wyxshuaibi%c*wyxshuaibi%c;
}
}
int main()
{
scanf("%lld%lld%lld",&a,&b,&c);
printf("%lld",doit(b));
return 0;
}
水过。