#include<iostream>
#include<cstring>
using namespace std;
long prime[2000];
bool isPrime(long N)
{
for(long i=2; i*i <= N; i++)
{
if(N%i == 0)return false;
}
return true;
}
int main()
{
int i,j,temp,count;
bool flag;
memset(prime,0,sizeof(long));
for( i=2,j=0; j<2000; i++)
{
if(isPrime(i)) {prime[j] = i; j++;}
}
//for(i=0; i<j; i++)cout<<prime[i]<<" ";
long N;
while(cin>>N)
{
count = 0;
cout<<N<<"=";
if(N==1)
cout<<1<<endl;
else
{
for(i=0; N!=1; i++)
{
temp = 0;
flag = false;
while( N%prime[i] == 0)
{
temp ++;
N /= prime[i];
flag = true;
}
if(count == 0)
{
if(flag)
{
count++;
if(temp > 1)
cout<<prime[i]<<"^"<<temp;
else
cout<<prime[i];
}
}
else
{
if(flag)
{
if(temp > 1)
cout<<"*"<<prime[i]<<"^"<<temp;
else
cout<<"*"<<prime[i];
}
}
}
cout<<endl;
}
}
return 0;
}
2-07. 素因子分解
最新推荐文章于 2023-12-12 21:53:16 发布