Beispiel #1
0
 private static long squareOfSumFrom1UpTo(int max) {
   return (long) Math.pow(Stream.rangeClosed(1, max).sum().longValue(), 2);
 }
Beispiel #2
0
 private static long sumOfSquaresFrom1UpTo(int max) {
   return Stream.rangeClosed(1, max).map(i -> (long) Math.pow(i, 2)).sum().longValue();
 }
Beispiel #3
0
 public static Stream<Long> primeFactors(long num) {
   return Stream.rangeClosed(2L, (int) Math.sqrt(num))
       .findFirst(d -> num % d == 0)
       .map(d -> Stream.cons(d, () -> primeFactors(num / d)))
       .orElseGet(() -> Stream.of(num));
 }