-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumDivisor.java
More file actions
29 lines (23 loc) · 776 Bytes
/
Copy pathSumDivisor.java
File metadata and controls
29 lines (23 loc) · 776 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
package Programmers;
import java.util.stream.IntStream;
class SumDivisor {
public int solution(int left, int right) {
int answer = 0;
int pos = IntStream.rangeClosed(left, right)
.filter(a ->
IntStream.rangeClosed(1, a)
.filter(b -> a % b == 0)
.count() % 2 == 0
)
.sum();
int neg = IntStream.rangeClosed(left, right)
.filter(a ->
IntStream.rangeClosed(1, a)
.filter(b -> a % b == 0)
.count() % 2 == 1
)
.sum();
answer = pos - neg;
return answer;
}
}