fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t;
  6. cin>>t;
  7. while(t--)
  8. {
  9. int n;
  10. cin>>n;
  11. int x, y;
  12. for(int i = sqrt(n); i >= 1; i--)
  13. {
  14. if(n % i == 0)
  15. {
  16. if(i*i == n)
  17. {
  18. x = i;
  19. y = i;
  20. break;
  21. }
  22. else
  23. {
  24. x = i;
  25. y = n/i;
  26. if(x*x == -y*y)
  27. {
  28. break;
  29. }
  30. }
  31. }
  32. }
  33. //if(x*x == -y*y)
  34. if((pow(x,y)*y+pow(y,x)*x)==n)
  35. {
  36. cout<<x<<" "<<y<<endl;
  37. }
  38. else
  39. {
  40. cout<<"-1"<<endl;
  41. }
  42. }
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0.01s 5388KB
stdin
5
3
7
42
31250
20732790
stdout
-1
-1
-1
-1
-1