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