Advertisement
noshin98

uva 1230

Dec 16th, 2016
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. long long bigmod(long long b,long long p,long long m)
  4. {
  5.     long long c;
  6.     if(p==0)
  7.         return 1;
  8.     if(p%2==1)
  9.     {
  10.         return ((b%m)*(bigmod(b,p-1,m)))%m;
  11.  
  12.     }
  13.     else
  14.     {
  15.         c =  bigmod(b ,p / 2, m);
  16.         return (c * c) % m;
  17.     }
  18. }
  19.  
  20.  
  21. int main()
  22. {
  23.     long long t, i,j,k,a,d,e;
  24.     while(scanf("%lld",&t)==1)
  25.     {
  26.         if(t==0)
  27.             break;
  28.         for(i=1;i<=t;i++)
  29.         {
  30.  
  31.             scanf("%lld %lld %lld",&a,&d,&e);
  32.             //k=bigmod(a,d,e);
  33.  
  34.             printf("%lld\n",bigmod(a,d,e));
  35.  
  36.         }
  37.     }
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement