Prime factor 1098

Subject description:

Enter an integer, the output of all of its prime factors

Enter a description:

An input series of integers (0,1, -1 excluded), each line a

Output Description:

The outputs of all prime factors, separated by a space between each factor, no space after the last factor

Sample input:

8

30

125

Sample output:

2 2 2

2 3 5

5 5 5

 1 #include<iostream>
 2 using namespace std;
 3 int main(){
 4     int n,i;
 5     while(cin>>n){
 6         for(i=2;i<n;i++){
 7             if(n%i==0){
 8                 cout<<i<<' ';
 9                 n=n/i;
10                 i--;
11             }
12         }
13         cout<<n;
14         cout<<endl;
15     }
16     return 0;
17 }
important

 

Guess you like

Origin www.cnblogs.com/zq-dmhy/p/10994195.html