题解 | #质数因子#

质数因子

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

#include <iostream>
#include <math.h>
using namespace std;

int main() {
    int a, b;
    while (cin >> a) { // 注意 while 处理多个 case

       if(a>=1&&a<2*10^9+15)
       {
           int old_a=a;
           for(int i=2;i<=sqrt(a);i++)
           {
                 if(a%i==0)
                {
                    cout<<i<<' ';
                    old_a=a/i;
                    a=old_a;
                    i=1;

                }
           }
            if(a==old_a)
            {
                cout<<a<<' ';
            }
               
       }
    }
    return 0;
}
// 64 位输出请用 printf("%lld")


全部评论

相关推荐

不愿透露姓名的神秘牛友
06-20 14:01
点赞 评论 收藏
分享
05-12 16:04
已编辑
江西财经大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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