CPP 15
F.cpp Guest on 26th September 2020 07:03:50 PM
  1. #include <cstdio>
  2. #include <cmath>
  3. #include <algorithm>
  4.  
  5. #define ll long long
  6.  
  7. using namespace std;
  8.  
  9. ll a, b, c;
  10.  
  11. /* int mpow(int b, int e, int m) {
  12.         int r = 1;
  13.         while (e > 0) {
  14.                 if (e&&1) r = (r*b)%m;
  15.                 e = e>>1;
  16.                 b = (b*b)%m;
  17.         }
  18.         return r;
  19. } */
  20.  
  21. ll pow2(ll x) {
  22.         return x*x;
  23. }
  24.  
  25. ll fexp(ll x, ll n) {
  26.         if (n == 0) return 1;
  27.         else if (n % 2 == 0) return (pow2(fexp(x, n>>1)))%c;
  28.         else return (x*fexp(x, n-1))%c;
  29. }
  30.  
  31. int main() {
  32.         //freopen("in.txt", "r", stdin);
  33.         int n;
  34.         scanf("%d", &n);
  35.         for (int i = 0; i < n; i++) {
  36.                 scanf("%lld %lld %lld", &a, &b, &c);
  37.                 //if (i) printf("\n");
  38.                 printf("%lld\n", (fexp(a, b)%c));
  39.         }
  40.         int lixo;
  41.         scanf("%d", &lixo);
  42.        
  43.         return 0;
  44. }

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.