题解 | #质数因子#
质数因子
http://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607
感觉复杂都有点高了
#include <iostream>
#include<math.h>
#include<vector>
int minZyz(int a);
using namespace std;
int main()
{
int n;
cin>>n;
vector<int> vec;
while(n>1){
int tmp = minZyz(n);
vec.push_back(tmp);
n = n/tmp;
}
for(auto it=vec.begin();it!=vec.end();++it)
cout<<*it<<" ";
return 0;
}
//求出最小质因子
int minZyz(int a){
int res=1;
int flag=1;
for(int i=2;i<=sqrt(a);i){
if(a%i==0){
for(int j=2;j<=sqrt(i);++j){
if(i%j==0){
flag=0;
break;
}
}
if(flag==0)
i++;
else
return i;
}
i++;
}
return a;
}