Blue Bridge Cup algorithm training ALGO-117 friendly number

Source: Internet
Author: User

Algorithm training friendly number time limit: 1.0s memory limit: 256.0MB The problem description has two integers, and if the approximate sum of each integer is equal to the other (except for itself), we call this logarithm friendly. For example:
9 Approximate and have: 1+3=4
4 Approximate and have: 1+2=3
So 9 and 4 are not friendly.
220 approximate and With: 1 2 4 5 10 11 20 22 44 55 110=284
284 Approximate and With: 1 2 4 71 142=220
So 220 and 284 are friendly.
Write a program to determine whether the two number is a friendly number. Input format One line, two integers, separated by a space output format if it is friendly number, output "yes", Otherwise output "no", Note does not include quotation marks. Sample input 220 284 sample output Yes data size and convention two integers are less than 10000 sample code:
1 Importjava.io.BufferedReader;2 Importjava.io.IOException;3 Importjava.io.InputStreamReader;4 5  public classMain {6      public Static voidMain (string[] Args)throwsIOException {7BufferedReader br =NewBufferedReader (NewInputStreamReader (system.in));8string[] str = br.readline (). split ("");9         intm = Integer.parseint (str[0]);Ten         intn = integer.parseint (str[1]); one         intSum_m =F (m); a         intSum_n =F (n); -          -         if(sum_m = = N && sum_n = =M) { theSystem.out.println ("yes"); -}Else -System.out.println ("no"); -          +     } -  +     Private Static intFintX) { a         intsum = 0; at          for(inti = 1; I < x; i++ ){ -             if(x% I ==0){ -Sum + =i; -             } -         } -         returnsum; in     } -      to}

Blue Bridge Cup algorithm training ALGO-117 friendly 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.