soyeonland 2024. 7. 7. 21:35

완전 탐색

1.수학적 규칙이 뭐가 있는지 고민해야함

2. range를 쓰면 예외 처리를 해야해서 (1로 나눌때), while 문으로 교체


#+2 씩
def solution(brown, yellow):
    answer = []
    # for i in range(1, yellow//2):
       # print(i)
    
    # for i in range(1, yellow//2+1):
    i=1
    while (i<=yellow//2+1):
        # print('i',i)
        if (yellow%i == 0):
            # print('i', i, 'yello%i', yellow%i)
            j = yellow//i # i, j brwon 후보
            if ((i+j)*2 + 4) == brown:
                # print('i',i , 'j', j, 'brown',brown)
                answer = [i+2,j+2]
        i+=1
    #answer = sorted(answer, lambda x:x[0])
    answer.sort(key=lambda x:x, reverse=True)
    return answer