-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.java
More file actions
44 lines (39 loc) · 1.09 KB
/
Copy pathtest.java
File metadata and controls
44 lines (39 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.util.*;
/*
判断x是否为完美数字,x为公差为1的等差数列的乘积,等差数列的长度至少为3
*/
public class test {
public static boolean isPerfect(long num) {
if (num < 6) {
return false;
}
for (long a = 1; num <= a * (a + 1) * (a + 2); a++) {
long product = a * (a + 1);
for (long i = a + 2;; i++) {
product *= i;
if (product == num) {
return true;
}
if (product > num||product<0) {
break;
}
}
}
return false;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
if (!sc.hasNextInt()) return;
int n = sc.nextInt();
while(n-->0){
if(!sc.hasNextLong()) break;
long num = sc.nextLong();
if(isPerfect(num)){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
sc.close();
}
}