#35517: c++


qqazwwsxeedcrrfvttgb@gmail.com (Jackis666)

學校 : 嘉義市私立輔仁高級中學
編號 : 226198
來源 : [42.73.47.160]
最後登入時間 :
2023-07-22 13:59:09
a010. 因數分解 | From: [163.27.10.252] | 發表日期 : 2023-06-05 19:12

#include<bits/stdc++.h>
using namespace std;
int main(){
    int num;
    cin>>num;
    while(num!=1){
        for(int i=2;i<=num;i++){
            if(num%i==0){
                num/=i;
                int down=1;
                while(num%i==0){
                    down++;
                    num/=i;
                }
                if(down==1 and num==1){cout<<i;}
                if(down!=1 and num==1){cout<<i<<"^"<<down;}
                if(down==1 and num!=1){cout<<i<<" * ";}
                if(down!=1 and num!=1){cout<<i<<"^"<<down<<" * ";}
            }
        }
    }
}

 
ZeroJudge Forum