题解
2025-01-26 19:38:07
发布于:广东
19阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int n;
bool vis[105];
bool flag ;
map<int,int>m;
vector <int>s;
void f(){
    for(int i=2;i<=100;i++){
        if(!vis[i]){
            s.push_back(i);
            for(int j=i*2;j<=100;j+=i)vis[j] = 1;
        }
    }
}
int main(){
    cin >> n;
    f();
    while(n-1){
        for(auto it : s){
            if(n%it==0){
                n/=it;
                m[it]++; 
            }
        }
    }for(auto it : m){
        if(!flag)flag = !flag;
        else cout << "*";
        if(it.second==1)cout << it.first;
        else cout << it.first<<"^"<<it.second;
    }
}
全部评论 1
正经题解
2025-01-26 来自 广东
0





有帮助,赞一个