[暖手][学习阶段-各路杂题][HDU-1164]Eddy's research I

来源:互联网 发布:js实现点击播放音乐 编辑:程序博客网 时间:2024/05/18 02:27

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
119412
 

Sample Output
112*2*13*181
 

import java.util.Arrays;import java.util.Scanner;public class Main {         public static boolean judge(int n ){int i;for(i=2;i<=Math.sqrt(n)+1;i++)if(n%i==0)return false;return true;}    public static void main(String args[]) {          Scanner in = new Scanner(System.in);    int[] num = new int[6542];    num[0]=2;    for(int i=3, j=1;i<=65535;i++)    if(judge(i))    {num[j]=i;j++;}       while(in.hasNext()){   int  n = in.nextInt();   boolean first = true;   if(judge(n))   {System.out.println(n);continue;}   while(!judge(n)){   for(int i =0;i<6542;i++)   if(n%num[i]==0)   {n/=num[i];   if(first){System.out.print(num[i]);first=false;}   else System.out.print("*"+num[i]);   break;}   }   System.out.println("*"+n);   }   }            }     



0 0
原创粉丝点击