当前位置:网站首页>Fundamentals of number theory and its code implementation
Fundamentals of number theory and its code implementation
2022-07-01 12:41:00 【51CTO】
List of articles
- Euclid
- Minimum common multiple
- Sieve to find the prime number ( Prime sieve )
- Basic theorem of arithmetic
- The permutation number of multiple sets
Euclid
Minimum common multiple
Sieve to find the prime number ( Prime sieve )
# Sieve to find prime number O(N)
# You can get 2-n The prime number in 1 Not prime
N
=
100010
primes
= [
0
for
i
in
range(
N)]
# Existential prime
st
= [
0
for
i
in
range(
N)]
# Has the current number been screened 0 Represents not being screened It shows that the number is a prime number Otherwise, it's not
def
get_primes(
n):
cnt
=
0
# Prime subscript
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.
Basic theorem of arithmetic
Every Greater than 1 The natural number of , If it's not itself, it's a prime number , It can be written as 2 More than one Prime number Product of , And after these qualitative factors are arranged in size , There is only one way to write .
for example 6 It can be written. 2 * 3
The permutation number of multiple sets
such as 1 1 2 2 3 What is the number of permutations
5! / 2! 2!1! = 10
边栏推荐
- [datawhale202206] pytorch recommendation system: recall model DSSM & youtubednn
- 队列的链式存储
- 类的初始化与实例化
- leetcode:241. Design priority for operation expression [DFS + Eval]
- "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
- kubernetes之ingress探索实践
- QT 播放器之列表[通俗易懂]
- Application of stack -- bracket matching problem
- Ansible的playbook
- Question d'entrevue de Huawei: recrutement
猜你喜欢

leetcode:226. 翻转二叉树【dfs翻转】

基于.NetCore开发博客项目 StarBlog - (13) 加入友情链接功能

"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

Use Net core access wechat official account development

队列的链式存储

项目部署,一点也不难!
![[today in history] July 1: the father of time sharing system was born; Alipay launched barcode payment; The first TV advertisement in the world](/img/41/76687ea13e1722654b235f2cfa66ce.png)
[today in history] July 1: the father of time sharing system was born; Alipay launched barcode payment; The first TV advertisement in the world

基于开源流批一体数据同步引擎 ChunJun 数据还原 —DDL 解析模块的实战分享

Double linked list related operations

I wish you all a happy reunion
随机推荐
[shell programming] - shell introductory learning
IOS interview
[Suanli network] technological innovation of Suanli Network -- key technology of operation service
木架的场景功能
CPI tutorial - asynchronous interface creation and use
队列的链式存储
Sort out relevant contents of ansible
简单斐波那契(递推)
華為面試題: 招聘
redis探索之缓存一致性
Eurake partition understanding
Switch basic experiment
【MAUI】为 Label、Image 等控件添加点击事件
2022-06-28-06-29
AI matting tool
Accept different views with an open mind
79. 单词搜索【dfs + 回溯visit + 遍历起点】
【历史上的今天】7 月 1 日:分时系统之父诞生;支付宝推出条码支付;世界上第一支电视广告
STM32 project practice (1) introduction and use of photosensitive resistor
R语言基于h2o包构建二分类模型:使用h2o.gbm构建梯度提升机模型GBM、使用h2o.auc计算模型的AUC值