#8431: 拜託幫幫忙,我不知道我哪裡錯~~


testtesttesttest (test)


#include<iostream>
using namespace std;
int main()
{int input;
while(cin>>input)
{int pow=0,flag=0;
for(int i=2;i<=input/2;i++)
{while(input%i==0)
{input/=i;
pow++;}
if(pow==0)continue;
else if(pow>1&&flag==0)
{cout<<i<<"^"<<pow;
flag=1;}
else if(pow=1&&flag==0)
{cout<<i;
flag=1;}
else if(pow>1&&flag==1)
{cout<<"*"<<i<<"^"<<pow;}
else if(pow=1&&flag==1)
{cout<<"*"<<i;}
}cout<<endl;}}
#8435: Re:拜託幫幫忙,我不知道我哪裡錯~~


MKshGoD (MKshGoD)


總覺得else if不太好..
用if、else試試看 
 
#include<iostream>
using namespace std;
int main()
{
int input;
while(cin>>input)
  {
   if(input>1)
   {
  
int flag=0;
for(int i=2;i<=input;i++)
   { 
   int pow=0;
while(input%i==0)
   {
   input/=i;
   pow++;
   }
if(pow==0)
continue;

if(pow>1){
    if(flag==0)  {
cout<<i<<"^"<<pow;
flag=1;
      }
      else
      {
cout<<"*"<<i<<"^"<<pow;
      }
}
else
{
if(flag==0)
      {
cout<<i;
flag=1;
      }

else
      {
cout<<"*"<<i;
      }
   
}

  }
  cout<<endl;
}
}
}