Problem Description
Eddy’s interest is very extensive, recently he is interested in prime number. Eddy discover the all number owned can be divided into the multiply of prime number, but he can’t write program, so Eddy has to ask intelligent you to help him, he asks you to write a program which can do the number to divided into the multiply of prime number factor .
Input
The input will contain a number 1 < x<= 65535 per line representing the number of elements of the set.
Output
You have to print a line in the output for each entry with the answer to the previous question.
Sample Input
11
9412
Sample Output
11
2*2*13*181
这个题的数据很水,不用判断素数也能过的。
直接for循环遍历几次2-n就可以了。
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(); for(int i=2;i*i<=n;i++)//如果一个数字不素数的话并且可以被两个或者两个以上的数字的乘积组成的话,那么它的组成部分一定小于等于该数的开根号. { if(n%i==0) { n=n/i; System.out.printf("%d*",i); i=1; } } System.out.printf("%d",n); System.out.println(); } } }