Pages

Wednesday, July 27, 2011

a010. 因數分解


/*
程式碼長度: 1538 Bytes
執行檔大小: 9121 Bytes
*/

#include
using namespace std;
#include

int main()
{
int input;
int p_input;
int pow=0;
int firstdigit=1;
int dividable=0;
while(cin>>input)
{
p_input=input;
for(int i=2;i<= p_input;i++)
{
while(p_input%i==0)
{
dividable=1;
pow++;
p_input = p_input/i;
}

if(dividable==1)
{
if(firstdigit==0)
{
cout<<" * ";
}
else
{
firstdigit=0;
}


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

}
}
firstdigit=1;
cout< }


return 0;
}

No comments:

Post a Comment