-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPerfection.java
More file actions
42 lines (34 loc) · 938 Bytes
/
Perfection.java
File metadata and controls
42 lines (34 loc) · 938 Bytes
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
package main.java.payapal;
public class Perfection {
private static Perfection perf;
public synchronized static Perfection getPerf() {
if (perf == null) {
perf = new Perfection();
}
return perf;
}
public static boolean isPerfect(long candidate) {
boolean retVal;
long[] divisors = GetDivisors(candidate);
int sum = 0;
for (int d = 0; d < 1000; d++)
{
sum = sum + divisors[d];
}
if (sum == candidate)
retVal = true;
return retVal;
}
private static long[] GetDivisors(long candidate) {
long[] divisors = new long[];
int d = 0;
for (long i = 0; i < candidate; i++) {
long foo = candidate / i;
if (foo * i == candidate) {
divisors[d] = i;
d = d + 1;
}
}
return divisors;
}
}