问题描述:
已知整数a、b、c。你的任务是求出区间[a,b]内的整数,满足该数与“该数的所有因数(不包括本身但包括1,1的因数和按0处理)相加之和”的差的绝对值小于等于c的数字。例如27的因数是1、3、9。那么27与27的所有因数和的差为:27-(1+3+9)=14。
输入与输出要求:
输入三个整数a、b、c。a、b代表所求区间范围,满足1<=a<=b<=10000,c代表限制条件,c>=0。输出满足条件的整数,每五个数为一行,整数之间用tab分隔,最后一个数后为换行符。当该区间没有符合条件的整数时,输出“There is no proper number in the interval.”
程序运行效果:
Sample 1:
1 10000 0↙
6 28 496 8128↙
Sample 2:
2000 5000 4↙
2048 2144 4030 4096↙
Sample 3:
900 1000 0↙
There is no proper number in the interval.↙
#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c;
int i,j;
int count=0;
scanf("%d %d %d",&a,&b,&c);
for(i=a;i<=b;i++){
int sum=0;
for(j=1;j<i;j++){
if(i%j==0) sum+=j;
}
if (fabs(i-sum)<=c) {
printf("%d\t",i);
count++;
}
if(count!=0&&count%5==0){
printf("\n");
}
}
if(count==0) printf("There is no proper number in the interval.\n");
return 0;
}