fork(1) download
  1. /*
  2.  * 素因数分解
  3.  *
  4.  * Author: Leonardone
  5.  */
  6. import java.util.*;
  7. import java.lang.*;
  8. import java.io.*;
  9.  
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. Scanner in = new Scanner(System.in);
  15.  
  16. StringBuilder sb = new StringBuilder();
  17.  
  18. while (in.hasNextInt())
  19. {
  20. int v = in.nextInt();
  21. seek(sb, v);
  22. }
  23.  
  24. System.out.print(sb);
  25. }
  26.  
  27. static int seek(StringBuilder sb, int v)
  28. {
  29. String op = " ";
  30. int c = 0;
  31. sb.append("" + v + " =");
  32. while (v % 2 == 0)
  33. {
  34. v /= 2;
  35. sb.append(op + "2");
  36. op = " * ";
  37. c++;
  38. }
  39. for (int k = 3; k <= v; k += 2)
  40. {
  41. while (v % k == 0)
  42. {
  43. v /= k;
  44. sb.append(op + k);
  45. op = " * ";
  46. c++;
  47. }
  48. }
  49. sb.append("\n");
  50. return c;
  51. }
  52. }
Success #stdin #stdout 0.11s 380736KB
stdin
12345
23459
23257
23711
38481
65536
12321
11111
11511
stdout
12345 = 3 * 5 * 823
23459 = 23459
23257 = 13 * 1789
23711 = 131 * 181
38481 = 3 * 101 * 127
65536 = 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2
12321 = 3 * 3 * 37 * 37
11111 = 41 * 271
11511 = 3 * 3 * 1279