첫 번째 풀이
def solution(r1, r2):
answer = 0
for i in range(-r2,r2+1):
for j in range(-r2,r2+1):
if r1**2 <= i**2 + j**2 <= r2**2:
answer += 1
return answer
두 번째 풀이
def solution(r1, r2):
answer = 0
for i in range(1,r2+1):
for j in range(1,r2+1):
if r1 <= (i**2 + j**2)**0.5 <= r2:
answer += 1
answer = (answer + r2 - r1 + 1)*4
return answer
세 번째 풀이
from math import ceil, floor
def solution(r1, r2):
answer = 0
for x in range(1,r2+1):
y_top = floor((r2**2-x**2)**0.5)
b_bot = ceil((r1**2-x**2)**0.5) if x<=r1 else 0
answer += y_top - b_bot + 1
return answer * 4