fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);
  9. cout.tie(0);
  10.  
  11. unordered_map<long long, pair<int, int>> f;
  12. for (int i = 2; i <= 1e6; i++)
  13. {
  14. long long sum = 1+i, cur = i, d = 2;
  15. while (sum <= 1e18)
  16. {
  17. if (cur > 1e18/i) break;
  18. cur *= i;
  19. sum += cur;
  20. if (sum > 1e18) break;
  21. if (f.find(sum) == f.end()) f[sum] = {i, d};
  22. d++;
  23. }
  24. }
  25.  
  26. int t;
  27. cin >> t;
  28. while (t--)
  29. {
  30. long long n;
  31. cin >> n;
  32. pair<long long, int> ans = {LLONG_MAX, 0};
  33. if (f.find(n) != f.end()) ans = f[n];
  34. long long delta = 1 + 4*n - 4;
  35. if (delta >= 0)
  36. {
  37. long double x = (sqrtl(delta)-1)/2.0;
  38. if (abs(x-round(x)) < 1e-9 && x > 1) ans = min(ans, {x, 2});
  39. }
  40. if (ans.first == LLONG_MAX) cout << -1;
  41. else cout << ans.first << ' ' << ans.second;
  42. cout << '\n';
  43. }
  44.  
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0.87s 83668KB
stdin
1
15241578873647311
stdout
123456789 2