• 카테고리

    질문 & 답변
  • 세부 분야

    알고리즘 · 자료구조

  • 해결 여부

    미해결

약수K, 시간 복잡도

23.01.24 06:05 작성 조회수 244

0

요렇게 하면 시간 복잡도를 줄일 수 있을 것 같아욤.

 

def input_function(line_string: str):
    n, k = map(int, line_string.split(' '))
    
    half_value: float = n ** 0.5
    temp_results: list[int] = []
    
    for value in range(1, int(half_value) + 1):
        if n % value == 0:
            temp_results.append(value)
            
    
    final_results: list[int] = []
    
    for i in temp_results:
        final_results.append(i)
        

    for i in temp_results[::-1]:
        final_results.append( 6 // i)
        
    if k > len(final_results):
        return -1
        
    return final_results[k-1]

 

 

답변 1

답변을 작성해보세요.

0

안녕하세요^^

n값이 6만 들어가는게 아닙니다. --> final_results.append( 6 // i)

그리고 n값이 제곱수일때 문제가 발생합니다. "36 7" 이런식으로 테스트해보세요.