唯一分解定理
2026-10-24 14:35:14
发布于:湖北
11阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n;
cin>>n;
long long t=n;
bool first=true; // 标记是否是第一个因子
for(long long i=2;i*i<=t;i++){
if(t%i==0){
int cnt=0;
while(t%i==0){
cnt++;
t/=i;
}
if(!first){
cout<<" * ";
}
first=false;
if(cnt>=2){
cout<<i<<'^'<<cnt;
}
else {
cout<<i;
}
}
}
// 如果t>1,说明t本身是一个质因子
if(t>1){
if(!first){
cout<<" * ";
}
cout<<t;
}
return 0;
}
这里空空如也



有帮助,赞一个