作者在 2013-10-28 20:01:21 发布以下内容
Problem Description
Input
输入数据的第一行为一个正整数T, 表示测试数据的组数. 然后是T组测试数据.
每组测试数据包含一个正整数n(n<999999999).
Output
按从小到大的顺序输出符合要求的n的因子,若无符合要求的因子,则输出“NO”。
Sample Input
3 18 12345 59Sample Output
2 3 6 9 3 5 15 823 2469 4115 NO
#include<iostream>
using namespace std;
const int x=1000000;//因为1000000数字大于int型的范围,所以需要把它移到int main外面
int a[x];
int main()
{
int t;
cin>>t;
for(int i=0;i<t;i++)
{
int n,j,k,cnt=0;
bool flag=false;
cin>>n;
for(j=2;j<n;j++)
{
if(n%j==0)
{
a[cnt++]=j;
flag=true;
}
}
if(flag==true)
{
for(k=0;k<cnt;k++)
{
cout<<a[k];
if(k!=cnt-1) cout<<" ";
}
}
else cout<<"NO";
cout<<endl;
}
return 0;
}
这题也可以作业处理,这留给读者自己思考了。