Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STEP 9. 약수, 배수와 소수 #10

Open
6 tasks done
letsjo opened this issue Mar 31, 2023 · 0 comments
Open
6 tasks done

STEP 9. 약수, 배수와 소수 #10

letsjo opened this issue Mar 31, 2023 · 0 comments
Assignees
Labels
STEP 단계

Comments

@letsjo
Copy link
Owner

letsjo commented Mar 31, 2023

단계 설명

약수와 배수는 정수론의 시작점이라고 할 수 있습니다.

문제 / 코드보기

새로 알게된 점

  • 소수 판별 방법1: 시간복잡도 O(N) 절반으로 줄이기

     def isPrime(number):
         if (number < 2):
             return False
         for i in range(2, math.ceil(number/2)+1):
             if (number % i == 0):
                 return False
         return True
  • 소수 판별 방법2: 시간복잡도 O(log N)

     def isPrime(number):
         if (number < 2):
             return False
         i = 2
         while (i*i <= number):
             if (number % i == 0):
                 return False
             i += 1
         return True
  • 에라토스테네스의 체: 소수 그룹 찾기

     def solution(number):
         # 처음엔 모든 수가 소수(True)인 것으로 초기화(0과 1은 제와)
         array = [True for i in range(number + 1)]
     
         # 에라토스테네스의 체 알고리즘
         for i in range(2, int(math.sqrt(number)) + 1):  # 2부터 n의 제곱근까지의 모든 수를 확인하며
             if array[i] == True:  # i가 소수인 경우(남은 수인 경우)
                 # i를 제외한 i의 모든 배수를 지우기
                 j = 2
                 while i * j <= number:
                     array[i * j] = False
                     j += 1
     
         return array
    
     array = solution(100)
    
     # 필요한 소수 범위 출력하기
     for i in range(60, 101):
         if array[i]:
             print(i, end=" ")
@letsjo letsjo added the STEP 단계 label Mar 31, 2023
@letsjo letsjo self-assigned this Mar 31, 2023
letsjo added a commit that referenced this issue Apr 1, 2023
letsjo added a commit that referenced this issue Apr 1, 2023
letsjo added a commit that referenced this issue Apr 1, 2023
letsjo added a commit that referenced this issue Apr 1, 2023
letsjo added a commit that referenced this issue Apr 1, 2023
letsjo added a commit that referenced this issue Apr 1, 2023
i*i 조건으로 시간복잡도 logN 으로 처리
letsjo added a commit that referenced this issue Apr 1, 2023
letsjo added a commit that referenced this issue Apr 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
STEP 단계
Projects
None yet
Development

No branches or pull requests

1 participant