Guest User

Untitled

a guest
Feb 17th, 2018
1,447
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. #define forn(i, n) for (int i = 0; i < int(n); i++)
  4.  
  5. using namespace std;
  6.  
  7. int getSqr(int x){
  8. int l = sqrt(x);
  9. for (int i = -2; i <= 2; ++i)
  10. if (l + i >= 0 && (l + i) * (l + i) == x)
  11. return l;
  12. return -1;
  13. }
  14.  
  15. void solve(){
  16. int x;
  17. scanf("%d", &x);
  18. for (int n = 1; n == 1 || n * n - (n / 2) * (n / 2) <= x; ++n){
  19. int lk = n * n - x;
  20. if (lk < 0) continue;
  21. int sq = getSqr(lk);
  22. if (sq <= 0) continue;
  23.  
  24. int k = n / sq;
  25. if (k > 0 && n * n - (n / k) * (n / k) == x){
  26. printf("%d %d\n", n, k);
  27. return;
  28. }
  29. }
  30.  
  31. puts("-1");
  32. }
  33.  
  34. int main() {
  35. int tc;
  36. scanf("%d", &tc);
  37. forn(i, tc)
  38. solve();
  39. }
RAW Paste Data