这题不用记录质数
2024-08-27 13:51:40
发布于:广东
5阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int p = 0;
void f(int n,int g){
if(n == 1){
return;
}
int b = n;
int x = 0;
for(;b % g == 0 and b > 0;x ++){
b /= g;
}
if(p == 0){
if(x > 1){
cout << g << "^" << x;
p = 1;
} else if(x == 1){
cout << g;
p = 1;
}
} else {
if(x > 1){
cout << "*" << g << "^" << x;
} else if(x == 1){
cout << "*" << g;
}
}
f(b,g + 1);
}
int main(){
int n;
cin >> n;
f(n,2);
return 0;
}
这里空空如也
有帮助,赞一个