fork download
  1. import java.util.*;
  2.  
  3. class Ideone
  4. {
  5. public static void main(String[] args)
  6. {
  7. int[] q = { 2017, 20017, 200017, 2000017, 20000017 };
  8. for (int i : q)
  9. hage(i);
  10. }
  11.  
  12. private static void hage(int n)
  13. {
  14. ArrayList<String>[] list = new ArrayList[n];
  15. for (int i = 2, j = (int) Math.sqrt(n); i <= j; i++)
  16. {
  17. for (long l = i * i, p = 2; l <= n; l *= i, p++)
  18. {
  19. int num = (int) l;
  20. if (list[num] == null) list[num] = new ArrayList<>();
  21. list[num].add(i + "^" + p);
  22. }
  23. }
  24.  
  25. boolean f = false;
  26. for (int i = 8; i <= n - 8; i++)
  27. {
  28. if (list[i] == null || list[n - i] == null) continue;
  29. for (String a : list[i])
  30. {
  31. for (String b : list[n - i])
  32. {
  33. System.out.printf("%s+%s=%d%n", a, b, n);
  34. f = true;
  35. }
  36. }
  37. }
  38.  
  39. System.out.println(f ? "" : "o^o+o^o= " + n + " is nothing\n");
  40. }
  41. }
Success #stdin #stdout 0.11s 711168KB
stdin
Standard input is empty
stdout
3^4+44^2=2017
9^2+44^2=2017
17^2+12^3=2017
12^3+17^2=2017
44^2+3^4=2017
44^2+9^2=2017

39^2+136^2=20017
3^8+116^2=20017
9^4+116^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

264^2+19^4=200017
264^2+361^2=200017
19^4+264^2=200017
361^2+264^2=200017

o^o+o^o= 2000017 is nothing

1644^2+4159^2=20000017
2904^2+3401^2=20000017
3401^2+2904^2=20000017
4159^2+1644^2=20000017