1037: 找出N之内的所有完数
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 719 Solved: 311
[ Submit][ Status][ Web Board]
Description
一个数如果恰好等于它的因子之和,这个数就称为"完数"。 例如,6的因子为1、2、3,而6=1+2+3,因此6是"完数"。 编程序找出N之内的所有完数,并按下面格式输出其因子:
Input
N
Output
? its factors are ? ? ?
Sample Input
1000
Sample Output
6 its factors are 1 2 3
28 its factors are 1 2 4 7 14
496 its factors are 1 2 4 8 16 31 62 124 248
28 its factors are 1 2 4 7 14
496 its factors are 1 2 4 8 16 31 62 124 248
#include<stdio.h>
#include<string.h>
int main()
{
int n,i,j,k,a[100],s=0;
scanf("%d",&n);
for(i=6;i<=n;i++)
{
for(j=1;j<i;j++)
{
if(i%j==0)
s=s+j;
}
if(s==i)
{
printf("%d ",i);
printf("its factors are ");
for(k=1;k<i;k++)
{
if(i%k==0)
printf("%d ",k);
}
printf("\n");
}
s=0;
}
}