解题思路:
注意事项:
参考代码:
import java.util.Scanner;
public class 亲和数 {
public static int f(int a,int b) {
int yes = 1;
int no = 2;
int sum = 0;
int sum1 = 0;
for(int i=1;i<=a/2;i++) {
if(a%i==0) {
sum = sum+i;
}
}
for(int l=1;l<=b/2;l++) {
if(b%l==0) {
sum1 = sum1+l;
}
}
if(sum==b&&sum1==a) {
return yes;
}else {
return no;
}
}
public static void main(String[] args) {
Scanner ic = new Scanner (System.in);
int m = ic.nextInt();
int l[] = new int[m];
for(int i=0;i<m;i++) {
int a = ic.nextInt();
int b = ic.nextInt();
l[i] = f(a,b);
}
for(int h=0;h<m;h++) {
if(l[h]==1) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}
}
0.0分
8 人评分
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)浏览:588 |
数列 (C++代码)浏览:664 |
C语言程序设计教程(第三版)课后习题8.9 (Java代码)浏览:1335 |
数组输出 (C语言代码)错误???浏览:565 |
用筛法求之N内的素数。 (C语言代码)浏览:1259 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:542 |
简单的a+b (C语言代码)浏览:581 |
C语言训练-亲密数 (C语言描述,反正怎么都能对)浏览:2169 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:577 |
川哥的吩咐 (C语言代码)浏览:611 |