#17476: java ac參考


k783242002@gmail.com (徐阿金)


參考qwer338859大大 改寫成自己比較好理解的

import java.util.Scanner;
public class test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

while (sc.hasNext()) {
  int i, t = 2,re=0; i = sc.nextInt();  
  while (i != 1){
    int count = 0;
    while (i % t == 0) {
     count++;
     i =i / t;
    }
  if (count > 0) {
   if (re==0) {
    System.out.print(t);
      if(count==1) System.out.print("");
      else System.out.print("^"+count);
      re++;
    } else {
    System.out.print(" * "+t);
      if(count==1) System.out.print("");
      else System.out.print("^"+count);
    }
  }
    t++;
   }
   System.out.println();
  }
 }
}