Hangzhou Electric Oj brush title (2040)

Amicable

Subject description:

Ancient Greek mathematician Pythagoras found in nature in several studies, all true divisor (i.e., not about its own number) of 220 and is:

1 + 2 + 4 + 5 + 10 + 11 + 20 + 22 + 44 + 55 + 110 = 284.

And all real number of about 284 is 1,2,4,71, 142, add up to exactly 220. It was very surprising for such a number, and called amicable. Generally speaking, the number of true if any of a number of about two numbers are another number and then the two numbers is amicable.

Your task is to write a program to determine whether a given two numbers are amicable

Input

The first line of input data comprises a number M, took M rows, each row one example, contains two integers A, B; where 0 <= A, B <= 600000;

Output

For each test example, if A and B are then output amicable YES, otherwise the output NO.

Sample Input

2 
220 284 
100 200

Sample Output

YES 
NO

By the answer:

#include <stdio.h>
int main ()
{
	int m,i,j,A,B,sum1,sum2;
	while(scanf("%d",&m)!=EOF)
	{
		for(i=0;i<m;i++){
			sum1=0;sum2=0;
			scanf("%d %d",&A,&B);
			for(j=1;j<A;j++){            //约数,又称因数。
				if(A%j==0){              //整数a除以整数b(b≠0) 除得的商正好是整数而没有余数,我们就说a能被b整除,或b能整除a。
					sum1+=j;             //a称为b的倍数,b称为a的约数。
				}
			}	
			for(j=1;j<B;j++){
				if(B%j==0){
					sum2+=j;
				}
			}	
			if((sum1==B)&&(sum2==A)){     //亲和数 
			    printf("YES\n");
		    }else{
			    printf("NO\n"); 
		    } 
		}
		
	}
	return 0;
}

 

Published 55 original articles · won praise 0 · Views 1000

Guess you like

Origin blog.csdn.net/ZhangShaoYan111/article/details/104224815