n是质数<=>n没有小于等于sqrt(n)的素因子

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int maxn=1e5+2;
 5 ll n;
 6 int ans[maxn];
 7 int main()
 8 {
 9     while(~scanf("%I64d",&n))
10     {
11         int cnt=0;
12         for(int i=2;i*i<=n;i++)
13         {
14             if(n%i==0)
15             {
16                 ans[cnt++]=i;
17                 while(n%i==0)
18                 {
19                     n/=i;
20                 }
21             }
22         }
23         if(n>1) ans[cnt++]=n;
24         for(int i=0;i<cnt;i++)
25         {
26             cout<<ans[i]<<" ";
27         }
28         cout<<endl;
29     }
30     return 0;
31 }
求一个很大的数的质因子

相关文章: