HDUEddy's research I

来源:互联网 发布:设计师 知乎 编辑:程序博客网 时间:2024/06/07 10:39

Eddy's research I

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10342    Accepted Submission(s): 6386


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
 
//方法一,耗时较短#include<iostream>#include<iomanip>using namespace std;int main() {ios_base::sync_with_stdio(false);cin.tie(0);int n,i;while(cin >> n) {for( i=2;; i++) {if(n==1) break;if(n % i==0) {cout << i;n = n/i;break;}}while(n!=1) {if(n%i==0) {cout << "*" <<i;n = n/i;}else {i++;}}cout << endl;}return 0;}
//方法二耗时长,将输入流解绑之后才勉强通过#include<iostream>#include<iomanip>using namespace std;int main() {ios_base::sync_with_stdio(false);cin.tie(0);int t,n,prime[7000];int flag = 1,i,j,p=0;for(i=2; i<=65521 ; i++) {flag = 1;for(j=2; j<i; j++) {if(i!=j&&i%j==0) {flag=0;break;}}if(flag) prime[p++] = i;}while(cin >> n) {t = n;while(n!=1) {for(int i=0;; i++) {if(n%prime[i]==0) {if(n!=t) cout <<"*";cout << prime[i];n = n/prime[i];break;}}}cout <<endl;}return 0;}


原创粉丝点击