After defining number: If a positive integer greater than 1 and equal to the sum of all the factors of its own, called the number is the number of complete, such as 6,28 are completed: 6 + 2 + 1 = 3; 28 = 1 + 2 + 4 + 7 + 14.
This task is to determine the number of question number End between two positive integers.
Input
input data comprising a plurality of rows, the first row is a positive integer n, the number of test cases, and n is the test case, one row for each instance, two positive integers num1 and num2 composition, (1 <num1 , num2 <10000).
Output
For each set of test data, and output between num1 num2 (including num1 and num2) number End number exists.
The Input the Sample
2
2. 5
. 5. 7
the Sample the Output
0
. 1
On the code:
#include <stdio.h>
int judge(int n) //判断是否是完数的函数
{
int i;
int sum = 0;
for(i=1; i<=n/2; i++)
{
if(n%i==0)
sum+=i;
}
if(sum == n)
return 1;
else
return 0;
}
int main()
{
int n;
int i;
int num1, num2;
while(scanf("%d", &n)!=EOF)
{
while(n--)
{
int count = 0;
scanf("%d%d", &num1, &num2);
int temp;
if(num1>num2) //比较大小,保证小数在前,大数在后
{
temp=num1;
num1=num2;
num2=temp;
}
for(i=num1; i<=num2; i++)
if(judge(i))
count++;
printf("%d\n", count);
}
}
return 0;
}
I believe we can achieve the algorithm, but this problem has a relatively pit place is the need to compare the size of the input two numbers and transposition, to ensure that the decimal in front, large numbers in prior to his A out.