质因数分解

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cmath>
 4 #include<cstdio>
 5 #include<algorithm>
 6 using namespace std;
 7 int main()
 8 {
 9     __int64 n,k,i,j;
10     while(scanf("%I64d",&n)!=EOF)
11     {
12         k=sqrt(n);j=0;
13         for(i=2;i<=k;i++)
14         {
15             if(n%i==0)
16             {
17                 cout<<i<<" ";
18             }
19             while(n%i==0)
20             {
21                 n/=i;//剔除重复的质因子
22             }
23         }
24         if(n!=1)
25         cout<<i<<endl;
26         else
27         cout<<endl;
28     }
29     return 0;
30 }
原文地址:https://www.cnblogs.com/WHLdbk/p/5683036.html