A^B Mod C
时间限制: 1 Sec 内存限制: 32 MB
Problem Description
给出3个正整数A B C,求A^B Mod C。
例如,3 5 8,3^5 Mod 8 = 3。
Input
3个正整数A B C,中间用空格分隔。(1 <= A,B,C <= 10^9)。
Output
输出计算结果。
Sample Input
3 5 8
Sample Output
3
#include<stdio.h> long long pow(long long a,long long b,long long c) { long long s=1; while (b) { if (b%2) { s=s*a%c; b--; } b/=2; a=a*a%c; } return s; } int main() { long long a,b,c; scanf("%lld%lld%lld",&a,&b,&c); printf("%lld\n",pow(a,b,c)); return 0; }