fork me on github

2040-亲和数(java)

http://acm.hdu.edu.cn/showproblem.php?pid=2040

 1 import java.util.Scanner;
 2 
 3 public class Main{
 4     public static void main(String[] args) {
 5         int n;
 6         Scanner scanner=new Scanner(System.in);
 7         n=scanner.nextInt();
 8         while(n>0){
 9             int a,b;
10             int sumA=1,sumB=1;
11             a=scanner.nextInt();
12             b=scanner.nextInt();
13             for(int i=2;i<=a/2;i++){
14                 if(a%i==0)
15                     sumA+=i;
16             }
17             if(sumA==b){
18                 for(int i=2;i<=b/2;i++)
19                     if(b%i==0)
20                         sumB+=i;
21                 if(sumB==a)
22                     System.out.println("YES");
23                 else
24                     System.out.println("NO");
25             }else
26                 System.out.println("NO");
27             n--;
28         }
29     }
30 }

 

posted @ 2017-07-04 22:00  烦嚣的人  阅读(634)  评论(0编辑  收藏  举报