fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static int makezeroDP(int n){
  11. int[] table = new int[n+1];
  12. table[1] = 1; table[2] = 2; table[3] = 3;
  13. int res;
  14. for (int i = 4; i <= n; i++) {
  15. res = 1 + table[i-1];
  16. int a = 2;
  17. while (a * a <= i) {
  18. if (i % a == 0)
  19. res = Math.min(res, 1 + table[i / a]);
  20. a += 1;
  21. }
  22. table[i] = res;
  23. }
  24. return table[n];
  25. }
  26.  
  27. public static void main (String[] args) throws java.lang.Exception
  28. {
  29. int n = 145;//999999;
  30. System.out.println(makezeroDP(n));
  31. }
  32. }
Success #stdin #stdout 0.07s 47004KB
stdin
Standard input is empty
stdout
6