当前位置:网站首页>数论基础及其代码实现
数论基础及其代码实现
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
边栏推荐
- VS Code 设置代码自动保存
- 单点登录SSO与JWT好文整理
- [some notes]
- redis探索之缓存一致性
- Tencent Li Wei: deeply cultivate "regulatory technology" to escort the steady and long-term development of the digital economy
- 【脑洞大开】《西潮》及《走向世界丛书》
- (混更一篇)多个txt文本转一个表格
- Sort out relevant contents of ansible
- Onenet Internet of things platform - mqtts product equipment connected to the platform
- Blue Bridge Cup multi interface switching processing (enumeration plus state machine method)
猜你喜欢

Common chart usage of Bi tools

顺序表有关操作

比特熊直播间一周年,英雄集结令!邀你来合影!

Ipv6-6to4 experiment

Self organization is the two-way rush of managers and members

codeforces -- 4B. Before an Exam

Machine learning - Data Science Library - day two

Use of easyexcel

BIM and safety in road maintenance-buildSmart Spain
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 3](/img/ea/c5e8d12007873385fa0d197fa62fd2.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 3
随机推荐
[106] 360 check font - check whether the copyright of local Fonts is commercially available
[20211129] jupyter notebook remote server configuration
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 2
系统测试UI测试总结与问题(面试)
Interpretation of hard threshold function [easy to understand]
How to install php7 and perform performance test using yum
比特熊直播间一周年,英雄集结令!邀你来合影!
The operation process of using sugar to make a large data visualization screen
How to use opcache, an optimization acceleration component of PHP
被锡膏坑了一把
Typora adds watermarks to automatically uploaded pictures
List of QT players [easy to understand]
Like the three foot platform
Using burpsuite to capture app packages
Pandas reads MySQL data
redis探索之缓存一致性
[Yu Yue education] financial management reference materials of Ningbo University of Finance and Economics
[shell programming] - shell introductory learning
6.30模拟赛总结
网络socket的状态要怎么统计?