HDU 2040: Affinity number

Source: Internet
Author: User

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


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

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

and 284 of all true approximate is 1, 2, 4, 71, 142, add up to exactly 220.

People were amazed at the number. and called affinity numbers. In general speaking. Assuming that the sum of the true approximations of a number is one of the two numbers, then the two numbers are the affinity numbers.

Your task is to write a program. Infer whether a given two number is a pro-numeric
Input data The first row includes a number m, followed by a M row, one instance per line, including two integers, a, B. Among them 0 <= a, b <= 600000;
Output for each test instance. Assuming that A and B are affinity numbers, the output is yes. Otherwise output No.
Sample Input

2220 284100 200

Sample Output
YESNO

A water problem.


#include <cstdio> #include <cstring> #include <algorithm> #include <iostream>using namespace Std;int ok;void tt (int x, int y) {    int sum=0;    for (int i=1; i<=x/2; i++)    {        if (x%i==0)            sum+=i;    }    if (sum==y)        ok++;} int main () {    int n;    int a, B;    scanf ("%d", &n);    while (n--)    {        ok=0;        scanf ("%d%d", &a, &b);        TT (A, b);        TT (b, a);        if (ok==2)            printf ("yes\n");        else            printf ("no\n");    }    return 0;}





HDU 2040: Affinity number

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.