当前位置:网站首页>数论基础及其代码实现
数论基础及其代码实现
2022-07-01 12:35:00 【51CTO】
文章目录
- 欧几里得
- 最小公倍数
- 筛法求质数(质数筛)
- 算术基本定理
- 多重集的排列数
欧几里得
最小公倍数
筛法求质数(质数筛)
# 筛法求素数 O(N)
# 可以得到2-n内的质数 1不是质数
N
=
100010
primes
= [
0
for
i
in
range(
N)]
# 存素数
st
= [
0
for
i
in
range(
N)]
# 当前数有没有被筛过 0代表没有被筛过 说明该数是质数 否则不是
def
get_primes(
n):
cnt
=
0
# 质数下标
for
i
in
range(
2,
n
+
1):
if
not
st[
i]:
primes[
cnt]
=
i
cnt
+=
1
j
=
0
while
primes[
j]
*
i
<=
n:
st[
primes[
j]
*
i]
=
1
if
i
%
primes[
j]
==
0:
break
j
+=
1
get_primes(
100000)
for
i
in
range(
20):
print(
primes[
i])
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
算术基本定理
每个大于1的自然数,若不是本身就是质数,就是可写为2个以上的质数的积,而且这些质因子按大小排列之后,写法仅有一种方式。
例如 6 可以写成 2 * 3
多重集的排列数
比如1 1 2 2 3的排列数是多少
5! / 2! 2!1! = 10
边栏推荐
- 微信模拟地理位置_伪装微信地理位置
- Using burpsuite to capture app packages
- Stack-------
- Powerful, easy-to-use, professional editor / notebook software suitable for programmers / software developers, comprehensive evaluation and comprehensive recommendation
- 数字信号处理——线性相位型(Ⅱ、Ⅳ型)FIR滤波器设计(2)
- List of QT players [easy to understand]
- Chapter 14 signals (IV) - examples of multi process tasks
- [Yu Yue education] financial management reference materials of Ningbo University of Finance and Economics
- 编译调试Net6源码
- JPA and criteria API - select only specific columns - JPA & criteria API - select only specific columns
猜你喜欢
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 8](/img/16/e1a0a52964c8a55eb729469114fc60.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 8

Operations related to sequence table

队列操作---

C serialization simple experiment

MySQL common functions

Self organization is the two-way rush of managers and members
![Wechat applet reports an error: [rendering layer network layer error] pages/main/main Local resource pictures in wxss cannot be obtained through wxss. You can use network pictures, Base64, or < image/](/img/6a/fe448ca635690bc5260436546b588e.jpg)
Wechat applet reports an error: [rendering layer network layer error] pages/main/main Local resource pictures in wxss cannot be obtained through wxss. You can use network pictures, Base64, or < image/

Indefinite integral

How to use opcache, an optimization acceleration component of PHP

队列的链式存储
随机推荐
fatal error: execution: 没有那个文件或目录
网络socket的状态要怎么统计?
栈-------
Self organization is the two-way rush of managers and members
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 5
Onenet Internet of things platform - mqtts product equipment connected to the platform
Wechat simulated geographical location_ Camouflage wechat location
Blue Bridge Cup multi interface switching processing (enumeration plus state machine method)
Wechat applet - 80 practical examples of wechat applet projects
强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐
二叉树的链式存储
Machine learning - Data Science Library Day 3 - Notes
Blocking sockets的读写操作该怎么玩?
Circular linked list--
数字信号处理——线性相位型(Ⅱ、Ⅳ型)FIR滤波器设计(2)
Application of stack -- bracket matching problem
【datawhale202206】pyTorch推荐系统:精排模型 DeepFM&DIN
循环链表--
Double linked list related operations
Onenet Internet of things platform - the console sends commands to mqtt product devices