Advertisement
JouJoy

E

Dec 10th, 2021 (edited)
1,098
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int MAXN = 1000005;
  6. typedef long long ll;
  7. ll cuberoot(ll x) {
  8.     ll l = 0, r = MAXN;
  9.     while (l != r) {
  10.         ll m = (l + r + 1) / 2;
  11.         if (m * m * m > x) {
  12.             r = m - 1;
  13.         }
  14.         else {
  15.             l = m;
  16.         }
  17.     }
  18.     return l;
  19. }
  20.  
  21. int main()
  22. {
  23.     ios_base::sync_with_stdio(false); cin.tie(0);
  24.     int n;
  25.     cin >> n;
  26.     for (int i = 0; i < n; i++)
  27.     {
  28.         ll l, r;
  29.         cin >> l >> r;
  30.         ll x = cuberoot(l * r);
  31.         if (x * x * x != l * r) {
  32.             cout << "NO" << "\n";
  33.         }
  34.         else if (l % x == 0 && r % x == 0) {
  35.             cout << "YES" << "\n";
  36.         }
  37.         else {
  38.             cout << "NO" << "\n";
  39.         }
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement