你上面的解答怪怪的,我幫你做了一些調整:
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
while(cin>>a)
{
b=2;
int d=1;
while(a!=1)
{
c=0;
while(a%b==0)
{
a=a/b;
c=c+1;
}
if(c>0&&d==1)
{
if ( c > 1 )
cout <<b<< "^" << c ;
if ( c== 1 )
cout <<b;
d++;
}
else if(c>0)
{
if ( c > 1 )
cout << " * "<<b<< "^" << c ;
if ( c== 1 )
cout << " * " <<b;
}
b++;
}
cout<<endl;
}
}
你上面的解答怪怪的,我幫你做了一些調整:
#include
using namespace std;
int main()
{
int a,b,c;
while(cin>>a)
{
b=2;
int d=1;
while(a!=1)
{
c=0;
while(a%b==0)
{
a=a/b;
c=c+1;
}
if(c>0&&d==1)
{
if ( c > 1 )
cout <<b<< "^" << c ;
if ( c== 1 )
cout <<b;
d++;
}
else if(c>0)
{
if ( c > 1 )
cout << " * "<<b<< "^" << c ;
if ( c== 1 )
cout << " * " <<b;
}
b++;
}
cout<<endl;
}
}
thanks