问题及代码:
Eddy's research I
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 7 Accepted Submission(s) : 2
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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
Author
运行结果:
知识点总结:
一开始想到用穷举法,先写一个判断素数的函数,由于 1 < x<= 65535,所以穷举出x的质因数,按题目的形式输出就行了。
可是……超时了……
我看了半天没看出来哪还能优化,数了数我用了五个循环,是有点多,但是应该没啥影响啊。
再一看,我在第一个循环里就先判断是否为素数,是就输出原数,否就进入下面的拆分循环。
其实这一步是多余的,时间就浪费在这第一步判断中了,虽然我刚写这题的时候觉得这个判断很符合题意。然后我删除这第一个判断后,就AC了。
学习心得:
这题要用数组保存需要用的变量然后备用。