Skip to content

Commit fd7e36a

Browse files
authored
solve: 코딩테스트 문제 풀이 - 30일차
1 parent 8c01012 commit fd7e36a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public long solution(int r1, int r2) {
3+
long answer = 0;
4+
5+
// x=1~r2까지 세기 (사분면 안쪽만)
6+
for (int x = 1; x <= r2; x++) {
7+
long maxY = (long)Math.floor(Math.sqrt((long)r2 * r2 - (long)x * x));
8+
long minY = 0;
9+
if (x < r1) {
10+
minY = (long)Math.ceil(Math.sqrt((long)r1 * r1 - (long)x * x));
11+
}
12+
answer += (maxY - minY + 1);
13+
}
14+
15+
// 4사분면 대칭
16+
answer *= 4;
17+
18+
return answer;
19+
}
20+
}

0 commit comments

Comments
 (0)