题解 | #质数因子#

质数因子

http://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607

#include #include<math.h> #include int minZyz(int a); using namespace std;

int main() { int n; cin>>n; vector 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; }

全部评论

相关推荐

wu970:标准北漂配置,怎么看着装修风格有点像自如的😭
点赞 评论 收藏
分享
03-27 01:58
已编辑
西北工业大学 Java
在平静中度过当下:如果这个bg也简历挂的话可能他们现在不缺人了吧,我也是这两天投的,阿里和快手投的岗都是简历秒挂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务