Input Specification:
Each input file contains one test case which gives a positive integer N in the range of long int.
Output Specification:
Sample Input:
97532468
Sample Output:
97532468=2^211171011291
Note
- 题意分解成因式,从小到大排列
- 注意质数 即 素数 prime
Code
#include<iostream>
#include<cmath>
using namespace std;
struct node{
int base;
int time;
}output[10001000];
int main(){
long long input;
long long cnt = 0;
cin >> input;
long long temp = input;
long long i = 2;
while(input > 1){
int flag = 0;
while(input % i == 0){
input /= i;
if(flag == 0){
flag = 1;
output[cnt].time = 1;
output[cnt].base = i;
}else
output[cnt].time++;
}
if(flag == 1) cnt++;
i++;
}
cout << temp << "=";
if(input == temp){ cout << temp; return 0;}
for(int i = 0; i < cnt; i++){
if(output[i].time > 1) cout << output[i].base << "^" << output[i].time;
else cout << output[i].base;
if(i < cnt -1 )cout << "*";
}
return 0;
}