当前位置:网站首页>数论基础及其代码实现
数论基础及其代码实现
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
边栏推荐
- Good luck brought by years of persistence
- 强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐
- 華為面試題: 招聘
- 循环链表--
- Self organization is the two-way rush of managers and members
- Compile and debug net6 source code
- IOS interview
- [20211129] configuration du serveur distant du carnet de notes jupyter
- "Analysis of 43 cases of MATLAB neural network": Chapter 40 research on prediction of dynamic neural network time series -- implementation of NARX based on MATLAB
- Switch basic experiment
猜你喜欢

【datawhale202206】pyTorch推荐系统:精排模型 DeepFM&DIN

STM32 project practice (1) introduction and use of photosensitive resistor

第十四章 信号(四)- 多进程任务示例

队列操作---

Onenet Internet of things platform - mqtt product equipment upload data points
![[106] 360 check font - check whether the copyright of local Fonts is commercially available](/img/a7/615e8000647b56f03a6a1d3dd81b6d.jpg)
[106] 360 check font - check whether the copyright of local Fonts is commercially available

MySQL common functions

MySQL workbench data modeling function

JS reverse | m3u8 data decryption of a spring and autumn network
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 2](/img/2b/f42ac6745eb126254af62ad5217f70.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 2
随机推荐
[datawhale202206] pytorch recommendation system: multi task learning esmm & MMOE
Pandas reads MySQL data
redis探索之缓存一致性
2022-06-28-06-29
Compile and debug net6 source code
单点登录SSO与JWT好文整理
被锡膏坑了一把
System test UI test summary and questions (interview)
BIM and safety in road maintenance-buildSmart Spain
Sort out relevant contents of ansible
Accept different views with an open mind
Blue Bridge Cup multi interface switching processing (enumeration plus state machine method)
【MAUI】为 Label、Image 等控件添加点击事件
Onenet Internet of things platform - mqtts product equipment connected to the platform
Virtualenv+pipenv virtual environment management
Eurake分区理解
Wechat applet - 80 practical examples of wechat applet projects
[Suanli network] technological innovation of Suanli Network -- key technology of operation service
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 2
Blocking sockets的读写操作该怎么玩?