ji-0630 / CodingTest

코딩테스트 연습 기록
0 stars 0 forks source link

소인수분해 #135

Closed ji-0630 closed 1 year ago

ji-0630 commented 1 year ago

문제 설명

image image

ji-0630 commented 1 year ago

나의 풀이

for i in a:
        while n%i==0:
            if i not in answer:

                answer.append(i)
            n=n//i
ji-0630 commented 1 year ago

다시 풀기

def solution(n):
    answer = []
    i = 2

    while (n != 1):
        if n % i == 0:
            n = n//i
            answer.append(i)
        else:
            i += 1
    return sorted(list(set(answer)))