#25710: 很簡單的 AC


s910251@student.cysh.cy.edu.tw (吳亮佑)

School : 國立嘉義高級中學
ID : 145844
IP address : [36.232.101.212]
Last Login :
2021-04-26 20:52:21
a010. 因數分解 | From: [36.232.101.212] | Post Date : 2021-06-15 14:17

count表示次方,如果次方=1就不用印"^"了

 

#include <iostream>

using namespace std;

 

int main(){

int n;

cin>>n;

for(int i = 2; i <= n; i ++){

int count = 0;

while(n % i == 0){

n /= i;

count++;

}

if(count >= 2){

cout<<i<<"^"<<count;

if(n !=1){

cout<<" * ";

}

}else if(count == 1){

cout<<i;

if(n !=1){

cout<<" * ";

}

}else{

 

}

}

return 0;

}

 
ZeroJudge Forum