HDACM1164
这一题,没必要去求素数,完全可以直接求。
比如:120 从i=2开始 120/2 =60,60/2=30,30/2=15,
(15%2!=0)i++,15/3=5,(5%3!=0)i++,(5%4!=0)i++,5/5=0;
120=2*2*2*3*5。
import java.util.Scanner;public class Main{public static void main(String[] args) {Scanner sc = new Scanner(System.in);while (sc.hasNext()) {int n = sc.nextInt();int i = 2;boolean isFirst = true;while (i<=n) {if (n%i==0) {n /= i;if (isFirst) {System.out.print(i);isFirst = false;continue;}System.out.print("*"+i);}else {i++;}}System.out.println();}}
}