Files
python/C++课程/第十六课循环结构程序设计实例2/所有质数因子.cpp

24 lines
288 B
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include<bits/stdc++.h>
using namespace std;
int main() {
int n,i;
n=12;
printf("%d=",n);
while(n%2==0) {
printf("%d*",2);
n/=2;
}
for(i=3; i<=sqrt(n); i+=2) {
if(n%i==0) {
n/=i;
printf("%d*",i);
i-=2;
}
}
printf("%d\n",n);
return 0;
}