11 Machine test of Beihang--to find the number of twins in the specified interval

Source: Internet
Author: User

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;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.