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

o^o+o^o= 2000000017 is nothing