HDUOJ: 2040 amicable

Copyright: qq836678589 https://blog.csdn.net/weixin_43924623/article/details/90693474

亲和数
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 57787 Accepted Submission(s): 35159

Problem Description

The ancient Greek mathematician Pythagoras in the number of studies found in nature, all true about the number (that is, not about the number itself) 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
Input data of the first line contains 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

#include<iostream>
using namespace std;
int sum(int a){
	int i,aum=0;
	for(int i=1;i<=a/2;i++){
		if(a%i==0)aum+=i;
	}
	return aum;
}
int main(){
	int a,n,m;
	cin>>a;
	while(a--){
		cin>>n>>m;
		if(sum(n)==m && sum(m)==n){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
} 

** Summary: ** we must first know what is true about the number, in addition to 1 and itself outside can be called their number divisible by the number really about.

Guess you like

Origin blog.csdn.net/weixin_43924623/article/details/90693474