#include "stdio.h"
int main(int argc,char *argv[]){
int m,n,t,mm,k;
printf("Input m & n(0if(scanf("%d%d",&m,&n)!=2 || m<1 || n<1 || n>1000 || m>n){
printf("Input error, exit...\n");
return 0;
}
printf("\n");
for(;m<=n;m++){
for(t=1,mm=m/2,k=2;k<=mm;k++)
if(m%k==0)
t+=k;
if(t==m && m!=1)
printf("%d\n",m);
}
return 0;
}
运行样例:
#include
int wanshu(int num)
{
int i,result=0;
for(i=1;i<=num/2;i++)
if(num%i==0) result+=i;
return result==num;
}
int main()
{
int i,m,n;
scanf("%d%d",&m,&n);
for(i=m;i<=n;i++)
if(wanshu(i))
printf("%d\n",i);
}
#include
int main()
{int i,j,s;
for(i=2;i<=1000;i++)
{s=1;
for(j=2;j<=i/2;j++)
if(i%j==0)s+=j;
if(s==i)printf("%d\n",i);
}
return 0;
}