题解 | #质数因子#
质数因子
https://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607
#include <iostream>
//#include <array>
//#include<vector>
#include <cmath>
using namespace std;
//std::array<int, 29> yinzi = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 39, 41, 43, 47, 53, 57, 59, 61, 67, 71, 73, 79, 83, 87, 89, 91, 97};
int main() {
unsigned int n;
//vector<int> nums;
while (cin >> n) { // 注意 while 处理多个 case
unsigned a = 2;
unsigned b = n;
//cout << b;
while(a <= sqrt(b)+1){
while(b % a == 0){
b = b/a;
cout<<a<<" ";
//nums.push_back(a);
}
a++;
}
if(b!=1){
cout<<b<<endl;
}
}
}
// 64 位输出请用 printf("%lld")
查看16道真题和解析