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. int flag = 0;
  13. for(int i = 1; i <= n; i++)
  14. {
  15. for(int j = 1; j <= n; j++)
  16. {
  17. if(pow(i, j)*j + pow(j, i)*i == n)
  18. {
  19. x = i;
  20. y = j;
  21. flag = 1;
  22. break;
  23. }
  24. }
  25. if(flag == 1)
  26. {
  27. break;
  28. }
  29. }
  30. if(flag == 1)
  31. {
  32. cout<<x<<" "<<y<<endl;
  33. }
  34. else
  35. {
  36. cout<<"-1"<<endl;
  37. }
  38. }
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0.66s 5556KB
stdin
5
3
7
42
31250
20732790
stdout
-1
-1
1 21
1 15625
1 10366395