2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
27
Task/Amicable-pairs/Java/amicable-pairs.java
Normal file
27
Task/Amicable-pairs/Java/amicable-pairs.java
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import java.util.Map;
|
||||
import static java.util.function.Function.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static java.util.stream.LongStream.*;
|
||||
|
||||
public class AmicablePairs {
|
||||
|
||||
public static void main(String[] args) {
|
||||
final int limit = 20_000;
|
||||
|
||||
Map<Long, Long> map = rangeClosed(1, limit)
|
||||
.parallel()
|
||||
.boxed()
|
||||
.collect(toMap(identity(), AmicablePairs::properDivsSum));
|
||||
|
||||
rangeClosed(1, limit)
|
||||
.forEach(n -> {
|
||||
long m = map.get(n);
|
||||
if (m > n && m <= limit && map.get(m) == n)
|
||||
System.out.printf("%s %s %n", n, m);
|
||||
});
|
||||
}
|
||||
|
||||
public static Long properDivsSum(long n) {
|
||||
return rangeClosed(1, (n + 1) / 2).filter(i -> n % i == 0).sum();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue