次方求模
时间限制:
1000 ms | 内存限制:
65535 KB
难度:
3
-
描述
-
求a的b次方对c取余的值
-
输入
-
第一行输入一个整数n表示测试数据的组数(n<100)
每组测试只有一行,其中有三个正整数a,b,c(1=<a,b,c<=1000000000)
输出
- 输出a的b次方对c取余之后的结果 样例输入
-
3 2 3 5 3 100 10 11 12345 12345
样例输出
-
3 1 10481
来源
代码:
#include<stdio.h> #include<math.h> int pow_mod(int a,int b,int c) { if(b==0) return 1; long long t=pow_mod(a,b>>1,c); if(b&1) return t*t%c*a%c; else return t*t%c; } int main() { int n,a,b,c; scanf("%d",&n); while(n--) { scanf("%d%d%d",&a,&b,&c); printf("%d\n",pow_mod(a,b,c)); } return 0; }
-
第一行输入一个整数n表示测试数据的组数(n<100)