11 computer problems in Beihang
"Problem description"
Twin number definition: If a divisor (factor, which contains 1, but does not contain the sum of a itself) equals B, the sum of the divisors (factors) of B equals a, and a and B are called Twins (A and B are not equal). Try to find the number of twins between the positive integers M and N.
Input:
Enter two positive integers M and N (1<=m<n<=20000) from the console, separated by a space in the middle.
Output:
Outputs a pair of all pairs of twins (including M and N) that match the subject description of M and n on the standard output. Output a pair of twins per line, separated by a space, small first output, the number of twins in accordance with the first number of small to large order output, a pair of twins output only once. The output string "None" if there is no twinning pair that meets the requirements.
Input sample
20 300
200 250
Output sample
220 284
NONE
Sample Description
Sample 1 enters an interval of [20,300] with a pair of twins, namely: 220 (1+2+4+5+10+11+20+22+44+55+110=284) and 284 (1+2+4+71+142=220). Example 2 the input interval is [200,250], in which there is no twin pairs, so the output string: None.
#include <stdio.h>
#include <stdlib.h>
int yinzisum (int x) {
int i=1,sum=0;
if (x==1) return
1;
while (i<x) {
if (x%i==0)
sum+=i;
i++;
}
return sum;
}
int main () {
int x,y;
int i,j;
int flag=0;
scanf ("%d%d", &x,&y);
int Min,max;
if (x>y) {
max=x;
min=y;
} else{
max=y;
min=x;
}
int *array= (int *) malloc (sizeof (int) * (max-min+1));
for (i=0;i<max-min+1;i++)
array[i]=yinzisum (min+i);//Store The factor of the interval number in the array for
(i=0;i<max-min+1;i++) {
for (j=i+1;j<max-min+1;j++) {
if (array[i]==j+min&&array[j]==i+min) {
printf ("%d%d\n", I +min,j+min);
Flag=1
}
}} if (flag==0)
printf ("none\n");
return 0;
}