#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char *argv[])
{
int a;
int b;
while(cin >> a)
{
for(int i=2;i<=a;i++)
{
b=1;
while(a%i==0)
{
cout << i;
a/=i;
while(a%i==0)
{
tryagain:
b++;
a/=i;
if(a%i==0)
{
goto tryagain;
}
else
{
cout << "^" << b;
}
}
}
while(a==1)
{
cout << endl;
}
cout << " * ";
}
}
}
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char *argv[])
{
int a;
int b;
while(cin >> a)
{
for(int i=2;i<=a;i++)
{
tryagain1:
b=1;
if(a%i==0)
{
cout << i;
a/=i;
while(a%i==0)
{
tryagain:
b++;
a/=i;
if(a%i==0)
{
goto tryagain;
}
else
{
cout << "^" << b;
}
}
}
else
{
i++;
goto tryagain1;
}
if(a==1)
{
cout << endl;
}
else
{
cout << " * ";
}
}
}
}
阿哈,不小心打錯了,這個給大家拿來參考