fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5. public static void ApplyFTA(int n) {
  6.  
  7. int fm, i = 2;
  8.  
  9. while(!(n == 1)) {
  10.  
  11. fm = 0;
  12.  
  13. while(n % i == 0) {
  14.  
  15. n /= i;
  16.  
  17. fm += 1;
  18.  
  19. }
  20.  
  21. if( fm != 0 ) System.out.println(i + " ^ " + fm);
  22. i += 1;
  23. }
  24. }
  25.  
  26. public static void main(String args[]) {
  27.  
  28. System.out.println("Fundamental Theorem of Arithmetic");
  29.  
  30. System.out.print("N = ");
  31.  
  32. Scanner keyboard = new Scanner( System.in );
  33.  
  34. int n = keyboard.nextInt();
  35.  
  36. ApplyFTA( n );
  37. }
  38. }
  39.  
Success #stdin #stdout 0.2s 60920KB
stdin
20
stdout
Fundamental Theorem of Arithmetic
N = 2 ^ 2
5 ^ 1