Advertisement
Emiliatan

e097

Apr 15th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. /* e097            */
  2. /* AC (2ms, 180KB) */
  3. #include <cstdio>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. typedef unsigned long long uint64;
  9.  
  10. const int SIZE = 32000;
  11.  
  12. int primes[SIZE], pointer, T, A, M, a, m, h, piPow_cnt, lim;
  13. uint64 b, c;
  14. bool notPrime[SIZE] = { true, true };
  15.  
  16. int main()
  17. {
  18.     for (int i = 2; i < SIZE; ++i)
  19.     {
  20.         if (!notPrime[i]) primes[pointer++] = i;
  21.         for (int j = 0; i * primes[j] < SIZE; ++j)
  22.         {
  23.             notPrime[i * primes[j]] = true;
  24.             if (i % primes[j] == 0) break;
  25.         }
  26.     }
  27.     scanf("%d %d %d", &T, &A, &M);
  28.     while (T-- && scanf("%d %d %d", &a, &m ,&h))
  29.     {
  30.         lim = sqrt(a);
  31.         b = c = 1;
  32.         for(int i = 0; primes[i] <= lim; ++i)
  33.             if(a % primes[i] == 0)
  34.             {
  35.                 piPow_cnt = 0;
  36.                 do
  37.                 {
  38.                     a /= primes[i], ++piPow_cnt;
  39.                 }while(a % primes[i] == 0);
  40.  
  41.                 piPow_cnt *= m;
  42.  
  43.                 for(int j = piPow_cnt % h; j; --j)
  44.                     c *= primes[i];
  45.  
  46.                 piPow_cnt /= h;
  47.  
  48.                 while(piPow_cnt--)
  49.                     b *= primes[i];
  50.             }
  51.         if(a != 1)
  52.         {
  53.             piPow_cnt = m;
  54.             for (int j = piPow_cnt % h; j; --j)
  55.                 c *= a;
  56.             piPow_cnt /= h;
  57.             while (piPow_cnt--)
  58.                 b *= a;
  59.         }
  60.         printf("%llu %llu\n", b, c);
  61.     }
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement