题解 | #质数因子#

质数因子

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

#include <iostream>
#include<cmath>
using namespace std;

// 搞清楚什么是质因子 https://baike.baidu.com/item/%E8%B4%A8%E5%9B%A0%E5%AD%90/10720836

int main() {
    long d;
    cin>>d;
    // while (cin >> a >> b) { // 注意 while 处理多个 case
    //     cout << a + b << endl;
    // }
    //一个数的质因数最多只有一个超过它的算术平方根
    for(long i=2; i<=sqrt(d) && i<=d; i++)
    {
        while(d%i==0)
        {
            // 是质因子
            cout<<i<<" "; //导致最后一位数字后也有空格
            d /= i;
        }
        
    }

    if(d>1)
    {
        cout<<d<<"";
    }

}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

自学java狠狠赚一...:骗你点star的,港卵公司,记得把star收回去
点赞 评论 收藏
分享
真烦好烦真烦:豆包润色了自己没看看吗,再说了,都说豆包是愚蠢且勤快的大学生,ds才是聪明的研究生,怎么敢让豆包写论文的
你们的毕业论文什么进度了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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