HDU 2040 affinity Number (Java)

Source: Internet
Author: User

Problem:

The start of J for the For Loop is set to the small root a, resulting in not all of the approximate numbers.


Affinity numberTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 26302 Accepted Submission (s): 15814


Problem Description
The ancient Greek mathematician Pythagoras found in the study of natural numbers that 220 of all true approximations (i.e. not their own approximations) sum to:

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

and 284 of all true approximations are 1, 2, 4, 71, 142, add up to exactly 220. People are amazed at the numbers and call it affinity numbers. Generally speaking, if any of the two numbers is the sum of the true approximations of the other number, then these two numbers are the affinity numbers.

Your task is to write a program that determines whether a given two number is a pro-and-numeric
Input data The first row contains a number m, followed by a M line, an instance of each row, containing two integers, a, a, 0 of which <= a, b <= 600000;
Output yes for each test instance if a and B are affinity numbers, otherwise output no.
Sample Input
2220 284100 200

Sample Output
YESNO


Code:

Import java.util.*;p ublic class main{public static void Main (string[] args) {Scanner cin=new Scanner (system.in); int n=cin . Nextint (); for (int i=0;i<n;i++) {int a=cin.nextint (); int b=cin.nextint (); int k=0,t=0;for (int j=1;j<a;j++) if (a% j==0) k=k+j;for (int j=1;j<b;j++) if (b%j==0) t=t+j;if (k==b&&t==a) System.out.println ("YES"); ElseSystem.out.println ("NO");}}}


HDU 2040 affinity Number (Java)

Related Article

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.