728x90
https://school.programmers.co.kr/learn/courses/30/lessons/181187
분석
풀이
from math import floor, sqrt
def solution(r1, r2):
tmp = 0
for i in range(0, r1):
tmp += int(sqrt(r2**2 - i**2)) - int(sqrt(r1**2 - i**2 - 1))
for i in range(r1, r2):
tmp += int(sqrt(r2**2 - i**2))
return tmp * 4
from math import floor, sqrt, ceil
def solution(r1, r2):
tmp=0
for x in range(1, r2+1):
y2= floor(sqrt(r2**2-x**2))
y1= ceil(sqrt(r1**2-x**2)) if x<r1 else 0
tmp+=y2-y1+1
return tmp*4
728x90