fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdint>
  4.  
  5. std::uint64_t MakeMaxPow(std::uint64_t Y) {
  6. std::uint64_t S = 0;
  7.  
  8. for (std::uint64_t i = 0; i < 64; i++) {
  9. if ((1ull << i) >= Y) return i;
  10. }
  11.  
  12. return 0xdeadbeef;
  13. }
  14.  
  15. bool MakeHoge(std::uint64_t Y) {
  16. bool F = false;
  17. std::uint64_t L = std::sqrt(Y)+1;
  18. std::uint64_t L2 = MakeMaxPow(Y);
  19. for (std::uint64_t A1 = 2; A1 <= L; A1++) {
  20. for (std::uint64_t B1 = 2; B1 <= L; B1++) {
  21. if (A1 + B1 > Y) break;
  22. for (std::uint64_t A2 = 2; A2 <= L2; A2++) {
  23. std::uint64_t PA = std::pow(A1, A2);
  24. if (PA > Y) break;
  25. for (std::uint64_t B2 = 2; B2 <= L2; B2++) {
  26. std::uint64_t PB = std::pow(B1, B2);
  27. if (PA + PB > Y) break;
  28. if (static_cast<std::uint64_t>(PA + PB) == Y) {
  29. std::cout << A1 << '^' << A2 << '+' << B1 << '^' << B2 << '=' << Y << std::endl;
  30. F = true;
  31. }
  32. }
  33. }
  34. }
  35. }
  36. if (!F) std::cout << "Can't Find the "<< Y << std::endl;
  37. return F;
  38. }
  39.  
  40. int main() {
  41. MakeHoge(2017);
  42. MakeHoge(20017);
  43. MakeHoge(200017);
  44. MakeHoge(2000017);
  45.  
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0.34s 3472KB
stdin
Standard input is empty
stdout
3^4+44^2=2017
9^2+44^2=2017
12^3+17^2=2017
17^2+12^3=2017
44^2+3^4=2017
44^2+9^2=2017
3^8+116^2=20017
9^4+116^2=20017
39^2+136^2=20017
81^2+116^2=20017
116^2+3^8=20017
116^2+9^4=20017
116^2+81^2=20017
136^2+39^2=20017
19^4+264^2=200017
264^2+19^4=200017
264^2+361^2=200017
361^2+264^2=200017
Can't Find the 2000017