https://app.codility.com/programmers/lessons/10-prime_and_composite_numbers/min_perimeter_rectangle/
- 직사각형 면적을 나타내는 정수 N
- N = A*B
- 2*(A+B)의 값들 중에서 최소 값 찾기
- O(sqrt(N))
import math
def solution(N):
minValue = float('inf')
value = 0
for D in range(1, int(math.sqrt(N))+1):
if N % D == 0:
if D*D == N:
value = 2*(D+D)
minValue = min(value, minValue)
break
else:
M = N//D
value = 2*(D+M)
minValue = min(value, minValue)
return minValue
'코딩테스트 > Codility' 카테고리의 다른 글
[codility] Lesson 15. Caterpillar method - AbsDistinct (0) | 2022.08.13 |
---|---|
[codility] Lesson 12. Euclidean algorithm - ChocolatesByNumbers (0) | 2022.08.13 |
[codility] Lesson 10. Prime and composite numbers - CountFactors (0) | 2022.08.13 |
[codility] Lesson 9. Maximum slice problem - MaxSliceSum (0) | 2022.08.13 |
[codility] Lesson 9. Maximum slice problem - MaxProfit (0) | 2022.08.13 |