Given a b and p, output (a^b) % p (2<=a<=100, 0<=b<=1000000000, 3<=p<=10000)
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- int quick_power(int a,int b,int p){
- int temp;
- if(b ==0){
- return1;
- }
- temp = quick_power(a, b /2, p);
- if(b &1){
- return(((temp * temp)% p)*(a % p))% p;
- }else{
- return(temp * temp)% p;
- }
- }
- int main(int argc,char*argv[]){
- int a, b, p;
- while(~scanf("%d%d%d",&a,&b,&p)){
- printf("%d\n", quick_power(a, b, p));
- }
- return0;
- }