题目地址: http://ac.jobdu.com/problem.php?pid=1060
//九度OJ 1060 完数VS盈数
//http://ac.jobdu.com/problem.php?pid=1060
#include<stdio.h>
#include<malloc.h>
int main()
{
int a[2][62]={0},i,j,n,flag,ans,temp,countw,county,sum;//a[0][]存放完数,a[1][]存放盈数
countw=county=0;
for(ans=2;ans<=60;ans++)
{
sum=1;
for(i=2;i<ans;i++)
{
if(!(ans%i))sum+=i;
}
if(sum==ans)a[0][countw++]=ans;
else if(sum>ans)a[1][county++]=ans;
}
for(i=flag=0;i<countw;i++)
{
if(flag)
{
printf(" %d",a[0][i]);
}
else
{
flag++;
printf("E: %d",a[0][i]);
}
}
printf("\n");
for(i=flag=0;i<county;i++)
{
if(flag)
{
printf(" %d",a[1][i]);
}
else
{
flag++;
printf("G: %d",a[1][i]);
}
}
return 0;
}