当前位置:网站首页>数论基础及其代码实现
数论基础及其代码实现
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
边栏推荐
- Leetcode (Sword finger offer) - 58 - ii Rotate string left
- 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/
- 关于NAND FLASH解扣的认识
- [Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 5
- Digital signal processing -- Design of linear phase (Ⅱ, Ⅳ) FIR filter (2)
- How to install php7 and perform performance test using yum
- MySQL common functions
- Queue operation---
- MySQL的零拷贝技术
- 2022-06-28-06-29
猜你喜欢

晓看天色暮看云,美图欣赏
![[20211129] jupyter notebook remote server configuration](/img/7c/79c9fcb91bde75e954dc3ecf9f5afd.png)
[20211129] jupyter notebook remote server configuration

C serialization simple experiment

Virtualenv+pipenv virtual environment management

How to install php7 and perform performance test using yum

I wish you all a happy reunion
![[Yunju entrepreneurial foundation notes] Chapter VII Entrepreneurial Resource test 1](/img/be/1194125442aaa2d7cc20b6a4a6762a.jpg)
[Yunju entrepreneurial foundation notes] Chapter VII Entrepreneurial Resource test 1

Circular linked list--

codeforces -- 4B. Before an Exam

【datawhale202206】pyTorch推荐系统:多任务学习 ESMM&MMOE
随机推荐
How to use opcache, an optimization acceleration component of PHP
fatal error: execution: 没有那个文件或目录
二叉树的链式存储
编译调试Net6源码
MySQL data table creation
A hole in solder paste
[20220605] Literature Translation -- visualization in virtual reality: a systematic review
Friends day 2022
Wechat simulated geographical location_ Camouflage wechat location
Mysql database knowledge collation
GPS 数据中的精度因子(DOP)与协方差之间的关系 (参考链接)
Tencent Li Wei: deeply cultivate "regulatory technology" to escort the steady and long-term development of the digital economy
数字信号处理——线性相位型(Ⅱ、Ⅳ型)FIR滤波器设计(2)
Common chart usage of Bi tools
华为面试题: 招聘
队列操作---
IOS interview
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 7
MySQL workbench data modeling function
Ansible相关内容梳理