acm题

因子分解

Description 找出输入整数的所有因子(包括重复因子),并按从小到大的顺序依次输出。

Input 输入一组待分解整数,每个整数k占一行。 保证所有的输入数字1 <= k < 2^21

Output 输出每个输入整数的所有因子(按因子从小到大的顺序输出),因子之间用空格隔开。

Sample Input 4 7 12

Sample Output 2 2 7 2 2 3

Code:
  1. #include<iostream>   
  2. #include<stdio.h>   
  3. using namespace std;   
  4. int main()   
  5. {   
  6.     int i,j,n;   
  7.     while (scanf("%d", &n)==1)    
  8.     {    
  9.         for(i=2;i<=n;i++)   
  10.         {   
  11.             for(;n>0;)   
  12.             {   
  13.                 if(n%i==0)   
  14.                 {   
  15.                     cout<<i<<" ";   
  16.                     n=n/i;   
  17.                 }   
  18.                 else    
  19.                     break;   
  20.             }   
  21.         }   
  22.         cout<<endl;   
  23.     }   
  24.     return 0;   
  25. }  

可是提交以后总显示wrong answer

作者:xwdreamer
欢迎任何形式的转载,但请务必注明出处。
分享到:
原文地址:https://www.cnblogs.com/xwdreamer/p/2297203.html