当前位置:网站首页>数论基础及其代码实现
数论基础及其代码实现
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
边栏推荐
- JS related interview questions and answers (1)
- CPI tutorial - asynchronous interface creation and use
- GPS 数据中的精度因子(DOP)与协方差之间的关系 (参考链接)
- Tencent security released the white paper on BOT Management | interpreting BOT attacks and exploring ways to protect
- Zero copy technology of MySQL
- Sleep quality today 79 points
- [JS advanced] promise explanation
- [Maui] add click events for label, image and other controls
- Question d'entrevue de Huawei: recrutement
- Chapter 14 signals (IV) - examples of multi process tasks
猜你喜欢

Stack-------
![[datawhale202206] pytorch recommendation system: recall model DSSM & youtubednn](/img/f2/7931952b832e84d7b8f2615906f33f.png)
[datawhale202206] pytorch recommendation system: recall model DSSM & youtubednn

Typora realizes automatic uploading of picture pasting

Onenet Internet of things platform - create mqtts products and devices

【语音信号处理】3语音信号可视化——prosody

IOS interview

手机便签应用

Virtualenv+pipenv virtual environment management
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 7](/img/41/e3ecbd49e4bfeab6c6e7d8733fe33a.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 7

A hole in solder paste
随机推荐
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 2
Zero copy technology of MySQL
codeforces -- 4B. Before an Exam
关于NAND FLASH解扣的认识
Onenet Internet of things platform - the console sends commands to mqtt product devices
GID:旷视提出全方位的检测模型知识蒸馏 | CVPR 2021
腾讯安全发布《BOT管理白皮书》|解读BOT攻击,探索防护之道
Onenet Internet of things platform - mqtt product equipment upload data points
【datawhale202206】pyTorch推荐系统:精排模型 DeepFM&DIN
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 7
QT 播放器之列表[通俗易懂]
fatal error: execution: 没有那个文件或目录
手把手教你完成图像分类实战——基于卷积神经网络的图像识别
C serialization simple experiment
[some notes]
强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐
【20211129】Jupyter Notebook遠程服務器配置
Sort out relevant contents of ansible
Indefinite integral
Machine learning - Data Science Library - day two