September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,19 +1,19 @@
|
|||
import java.util.Map;
|
||||
import static java.util.function.Function.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static java.util.stream.LongStream.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.LongStream;
|
||||
|
||||
public class AmicablePairs {
|
||||
|
||||
public static void main(String[] args) {
|
||||
final int limit = 20_000;
|
||||
int limit = 20_000;
|
||||
|
||||
Map<Long, Long> map = rangeClosed(1, limit)
|
||||
Map<Long, Long> map = LongStream.rangeClosed(1, limit)
|
||||
.parallel()
|
||||
.boxed()
|
||||
.collect(toMap(identity(), AmicablePairs::properDivsSum));
|
||||
.collect(Collectors.toMap(Function.identity(), AmicablePairs::properDivsSum));
|
||||
|
||||
rangeClosed(1, limit)
|
||||
LongStream.rangeClosed(1, limit)
|
||||
.forEach(n -> {
|
||||
long m = map.get(n);
|
||||
if (m > n && m <= limit && map.get(m) == n)
|
||||
|
|
@ -22,6 +22,6 @@ public class AmicablePairs {
|
|||
}
|
||||
|
||||
public static Long properDivsSum(long n) {
|
||||
return rangeClosed(1, (n + 1) / 2).filter(i -> n % i == 0).sum();
|
||||
return LongStream.rangeClosed(1, (n + 1) / 2).filter(i -> n % i == 0).sum();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue