ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

 

MinPerimeterRectangle coding task - Learn to Code - Codility

Find the minimal perimeter of any rectangle whose area equals N.

app.codility.com


๋ฌธ์ œ ํ’€์ด

Count Factor์˜ ๊ฒฝ์šฐ ์•ฝ์ˆ˜๋ฅผ ๋‹จ์ˆœํžˆ ์นด์šดํŠธ ํ•˜์˜€๋‹ค๋ฉด, ๋„“์ด๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ ๊ฐ€์žฅ ์ž‘์€ ๋‘˜๋ ˆ๋ฅผ ๊ฐ€์ง€๋Š” ๊ฒฝ์šฐ๋ฅผ ์ฐพ๋Š” ๋ฌธ์ œ์ด๋‹ค.

๋„“์ด๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, ๋‘ ๋ณ€์˜ ๊ธธ์ด๊ฐ€ ๋˜๋Š”๊ฒƒ์€ ๊ฐ๊ฐ์˜ ์•ฝ์ˆ˜ ์ด๋ฏ€๋กœ, ์•ฝ์ˆ˜ ์ค‘ ๊ฐ€์žฅ ํฐ ์•ฝ์ˆ˜๋ฅผ ํ†ตํ•ด ๊ณ„์‚ฐ๋œ ๋‘˜๋ ˆ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฉด ๋œ๋‹ค.

 


์ฝ”๋“œ

import math


def solution(N):
    for num in range(int(math.sqrt(N)), 0, -1):
        if N % num == 0:
            break

    return 2 * (num + N // num)
728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€