STUDY/Algorithm

[프로그래머스] LEVEL2 카펫, python3, 완전탐색

sinawi95 2019. 11. 20. 10:16
728x90

import math
def solution(brown, red):
    answer = []
    sq_red=int(math.sqrt(red))
    a,b=0,0
    for num in range(1,sq_red+1):
        flt_rv=red/num
        int_rv=red//num
        if flt_rv==int_rv:
            flt_bv=(brown+red)/(int_rv+2)
            int_bv=(brown+red)//(int_rv+2)
            if flt_bv==int_bv:
                b=int_bv
    a=(brown+red)//b
    answer=[a,b]
    return answer