mirror of
https://github.com/wczffl-503/OI-Codes.git
synced 2025-07-08 02:13:51 +08:00
更新了许多
This commit is contained in:
35
循环-分解质因式.cpp
Normal file
35
循环-分解质因式.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
using namespace std;
|
||||
int main(){
|
||||
int n,first=1,cnt=0;
|
||||
cin >>n;
|
||||
if(n==1){
|
||||
cout <<"1=1";
|
||||
return 0;
|
||||
}
|
||||
cout <<n<<"=";
|
||||
for(int i=2;i<=n;i++){
|
||||
while(n%i==0){
|
||||
cnt++;
|
||||
n/=i;
|
||||
}
|
||||
if(cnt>0){
|
||||
if(first!=1){
|
||||
cout <<"*";
|
||||
}
|
||||
else{
|
||||
first=0;
|
||||
}
|
||||
cout <<i;
|
||||
if(cnt>=2){
|
||||
cout <<"^"<<cnt;
|
||||
}
|
||||
cnt=0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user