因子分解
Description 找出輸入整數的所有因子(包括重複因子),并按從小到大的順序依次輸出。
Input 輸入一組待分解整數,每個整數k占一行。 保證所有的輸入數字1 <= k < 2^21
Output 輸出每個輸入整數的所有因子(按因子從小到大的順序輸出),因子之間用空格隔開。
Sample Input 4 7 12
Sample Output 2 2 7 2 2 3
Code:
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int i,j,n;
while (scanf("%d", &n)==1)
{
for(i=2;i<=n;i++)
{
for(;n>0;)
{
if(n%i==0)
{
cout<<i<<" ";
n=n/i;
}
else
break;
}
}
cout<<endl;
}
return 0;
}
可是送出以後總顯示wrong answer
本文轉自xwdreamer部落格園部落格,原文連結:http://www.cnblogs.com/xwdreamer/archive/2009/07/07/2297203.html,如需轉載請自行聯系原作者