HDU 2040 affinity

Source: Internet
Author: User
Problem description the ancient Greek mathematician pedgoras found in the study of natural numbers that the sum of all the true dikes of 220 (that is, not their own dikes) is:

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

The sum of all the true approx. Values of 284 is 1, 2, 4, 71, and 142, which is exactly 220. People are amazed at this kind of data and call it affinity. Generally, if either of the two numbers is the sum of the true approx. of the other, the two numbers are the affinity.

Your task is to write a program to determine whether the given two numbers are affinity.

 

The first row of input data contains a number of M, followed by m rows. Each row has an instance, which contains two integers, A and B. 0 <=a, B <=600000;

For each test instance, if A and B are the affinity numbers, output yes; otherwise, output No.

Sample Input

2220 284100 200
 

Sample output

YESNO

import java.io.BufferedInputStream;import java.util.*;public class Main {public static void main(String[] args) {Scanner sc=new Scanner(new BufferedInputStream(System.in));int k,m,n;k=sc.nextInt();for(int i=0;i<k;i++){m=sc.nextInt();n=sc.nextInt();fun(m,n);}}public static void fun(int m,int n){int sum1=0;int max=Math.max(m, n);int min=Math.min(m, n);for(int i=1;i<max;i++){if(max%i==0){sum1+=i;}}if(sum1==min) System.out.println("YES");else System.out.println("NO");}}

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.