Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. void analyse(int, int);
  7.  
  8. int main()
  9. {
  10.     int zestawy;
  11.     cin >> zestawy;
  12.     cin.ignore();
  13.     std::string line;
  14.     int s, a;
  15.     int pos;
  16.     for (int i = 0; i < zestawy; i++)
  17.     {
  18.         getline(cin, line);
  19.         pos = line.find(" ");
  20.         a = atoi(line.substr(0, pos).c_str());
  21.         s = atoi(line.substr(pos).c_str());
  22.         analyse(a, s);
  23.         line.clear();
  24.     }
  25.  
  26.     return 0;
  27. }
  28.  
  29. void analyse(int a, int s)
  30. {
  31.     int max = pow(a, 1.0 / s);
  32.     int c = 0;
  33.     for (int i = max; i; i--)
  34.     {
  35.         c = pow(i, s);
  36.         if (!(a % c))
  37.         {
  38.             cout << i << " " << a / c << "\n";
  39.             break;
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement