일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- 유체역학
- Fluid Dynamics
- Boundary Layers
- Compressible Flow
- Crank-Nicolson
- heap
- 디스크 컨트롤러
- regression
- 회귀
- Finite Difference Method
- projecteuler
- Turbulent
- Fluids
- 예제
- 프로그래머스
- Heat Equation
- Python
- FTCS
- Blasius
- python3
- Statistics
- Navier-Stokes
- Laminar
- 이중우선순위큐
- 우선순위큐
- programmers
- 힙
- 통계학
- 파이썬
- 프로젝트오일러
- Today
- Total
Sudal's Garage
Module: sympy 본문
프로젝트 오일러 문제들 중 소수, prime number, 가 등장하는 문제들이 제법 많다.
검색 좀 하다가 유용한 method를 sympy 모듈에서 발견하여
사용되는 method를 사용 할 때마다 여기에 적자!
출처: https://docs.sympy.org/latest/modules/ntheory.html
Number Theory
sympy.ntheory.generate.
Sieve
: An infinite list of prime numbers, implemented as a dynamically growing sieve of Eratosthenes. When a lookup is requested involving an odd number that has not been sieved, the sieve is automatically extended up to that number.
에라토스테네스의 체를 사용하여 무한한 소수의 list 를 generate한다.
예)
1 2 3 4 5 | >>> from sympy import sieve >>> 25 in sieve False >>> sieve._list array('l', [2, 3, 5, 7, 11, 13, 17, 19, 23]) | cs |
sieve.extend(n)
: n 이하 까지의 모든 소수
sieve.extend_to_no(n)
: n번째 소수까지의 모든 소수
sieve.primerange(a,b)
: a이상 b미만의 모든 소수
sieve.search(n)
: n이 소수인지 알려준다. 출력은 (i,j) 형태로 나오는데 i와 j가 같다면 소수이다.
primerange(a,b): a이상 b미만의 모든 소수를 generate
isprime(n): n이 소수인지 판별해준다. 출력형태는 Boolean.
divisor_count(n): n의 약수의 개수를 반환한다.
divisors(n): n의 약수를 list 형태로 반환한다.
sympy.functions.combinatorial.numbers
nC(n,k): , Combination
nP(n,k): , Permutation
example)
*sieve.primerange 와 primerange의 차이:
The Sieve method, primerange, is generally faster but it will occupy more memory as the sieve stores values. The default instance of Sieve, named sieve, can be used:
sieve.method 는 일반적으로 더 빠르지만, sieve가 값을 저장하기 때문에 더 많은 메모리를 저장한다.
최종 수정: 17:30 Mar 1, 2019
'Programming > python' 카테고리의 다른 글
Module: itertools (0) | 2019.03.02 |
---|---|
Module: Calendar (0) | 2019.03.02 |