티스토리 뷰
728x90
def is_prime(n):
if n == 2 or n == 3: return True
if n < 2 or n%2 == 0: return False
if n < 9: return True
if n%3 == 0: return False
r = int(n**0.5)
# since all primes > 3 are of the form 6n ± 1
# start with f=5 (which is prime)
# and test f, f+2 for being prime
# then loop by 6.
f = 5
while f <= r:
print('\t',f)
if n % f == 0: return False
if n % (f+2) == 0: return False
f += 6
return True
https://stackoverflow.com/questions/15285534/isprime-function-for-python-language/15285588
isPrime Function for Python Language
So I was able to solve this problem with a little bit of help from the internet and this is what I got: def isPrime(n): for i in range(2,int(n**0.5)+1): if n%i==0: return Fa...
stackoverflow.com
728x90
'공부' 카테고리의 다른 글
[Java] lombok @Data (0) | 2021.09.06 |
---|---|
[Mac] Terminal Hostname 변경 (0) | 2021.09.05 |
[Python] IsPrime (0) | 2021.09.05 |
[Java] new line replacement (0) | 2021.09.05 |
[Java] How to forward large files with RestTemplate? (0) | 2021.09.05 |
[Python] Tensorflow v1 (env v2) (0) | 2021.08.13 |
댓글
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- 142,048
- Today
- 28
- Yesterday
- 221
TAG
- follower
- 김달
- 유투브
- Bot
- wlw
- 인스타그램
- 책그림
- 메디파크 내과 전문의 의학박사 김영수
- 어떻게 능력을 보여줄 것인가?
- 팔로워 수 세기
- Kluge
- 개리마커스
- 연애학개론
- COUNT
- 클루지