方法1:
long int input;
while (cin>>input)
{
while (input!=1)
{
for (int i = 2; i <= input; ++i)
{
if (input%i == 0)
{
input /= i;
cout << i << ' ';
break;
}
}
}
}
方法2:
long int input;
while (cin>>input)
{
for (int i = 2; i <= input; ++i)
{
if (input%i == 0)
{
input /= i;
cout << i << ' ';
i = 1;
}
}
}
方法3:
long int input;
while (cin>>input)
{
for (int a = 2; a <= sqrt(input); a++)
{
while (input%a == 0)
{
cout << a << ' ';
input = input / a;
}
}
if (input>1) cout << input << ' ';
}