codinghatso

알고리즘 with python.01 본문

코테일지

알고리즘 with python.01

hatso 2021. 5. 20. 19:28

 

소수 나열하기


	input = 20
    
    
        # 소수는 자기 자신과 1외 에는 아무것도 나눌 수 없다.
        def find_prime_list_under_number(number):
            prime_list = [] 
            for n in range(2, number + 1):  # n의 범위 : 2부터 number까지
              for i in prime_list:  # i의 범위 : 2부터 n - 1까지
                  for i in prime_list:  # i의 범위 : 2부터 n - 1까지
                      if n % i == 0 and i * i  <= n:
                          break
                  else:
                      prime_list.append(n)
             return prime_list


          result = find_prime_list_under_number(input)
          print(result)
    

'코테일지' 카테고리의 다른 글

알고리즘 with python.06  (0) 2021.06.13
알고리즘 with python.05  (0) 2021.05.30
알고리즘 with python.04  (0) 2021.05.30
알고리즘 with python.03  (0) 2021.05.30
알고리즘 whit python.02  (0) 2021.05.30
Comments