-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution13.java
More file actions
31 lines (28 loc) · 938 Bytes
/
Solution13.java
File metadata and controls
31 lines (28 loc) · 938 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
30
31
/* 코딩 테스트 공부 - 13
* 정수 left와 right가 매개변수로 주어집니다.
* left부터 right까지의 모든 수들 중에서, 약수의 개수가 짝수인 수는 더하고, 약수의 개수가 홀수인 수는 뺀 수를 return 하도록 solution 함수를 완성해주세요.
*/
package codingTest;
public class Solution13 {
public static int solution(int left, int right) {
int answer = 0;
for(int i = left; i <= right; i++){
int num = 0;
for(int j = 1; j <= i; j++){
if(i % j == 0){
num++;
}
}
if(num % 2 == 0){
answer += i;
}
else{
answer -= i;
}
}
return answer;
}
public static void main(String[] args) {
System.out.println(solution(13, 17));
}
}