# 15.5. A bit of number theory with SymPy


```
from sympy import *
import sympy.ntheory as nt
init_printing()
```


```
nt.isprime(2017)
```




    True




```
nt.nextprime(2017)
```


```
nt.prime(1000)
```


```
nt.primepi(2017)
```


```
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
x = np.arange(2, 10000)
fig, ax = plt.subplots(1, 1, figsize=(6, 4))
ax.plot(x, list(map(nt.primepi, x)), '-k',
        label='$\pi(x)$')
ax.plot(x, x / np.log(x), '--k',
        label='$x/\log(x)$')
ax.legend(loc=2)
```


```
nt.factorint(1998)
```


```
2 * 3**3 * 37
```


```
from sympy.ntheory.modular import solve_congruence
solve_congruence((1, 3), (2, 4), (3, 5))
```

bec5e8a8820cc76f30f9cbdee2743076f2328494
ipynb
Jupyter Notebook
chapter15_symbolic/05_number_theory.ipynb
guoci/cookbook-2nd-code
1e6d8b1b66fcffa6362b13893bbd0e43f2829cb6
MIT
2018-02-01T09:16:45.000Z
2022-03-03T17:47:59.000Z
chapter15_symbolic/05_number_theory.ipynb
dnzengou/cookbook-2nd-code
85128694cdb9206b4325f95fe0060e01cf72e7f5
MIT
2019-03-11T09:47:21.000Z
2022-01-11T06:32:00.000Z
chapter15_symbolic/05_number_theory.ipynb
dnzengou/cookbook-2nd-code
85128694cdb9206b4325f95fe0060e01cf72e7f5
MIT
2018-02-13T03:17:05.000Z
2022-03-18T21:04:45.000Z
Qwen/Qwen-72B
1. YES
2. YES