class Solution {
public int solution(int left, int right) {
int answer = 0;
for(int i=left; i<=right; i++) {
int count = calc(i);
answer += count%2==0 ? i : -i;
}
return answer;
}
public int calc(int n) {
int count = 0;
for(int i=1; i<=n; i++) {
if(n%i==0) { count++; }
}
return count;
}
}
'Problem Solving > Programmers' 카테고리의 다른 글
[Level 1] 예산 (0) | 2022.03.24 |
---|---|
[Level 1] 3진법 뒤집기 (0) | 2022.03.23 |
[Level 1] 실패율 (0) | 2022.03.23 |
[Level 1] 폰켓몬 (0) | 2022.03.23 |
[Level 1] 체육복 (0) | 2022.03.23 |