栏目分类:
子分类:
返回
文库吧用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
文库吧 > IT > 面试经验 > 面试问答

是否有Python库列出素数?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

是否有Python库列出素数?

自问了这个问题之后,我围绕C
++库primesieve编写了Python包装器。https://github.com/hickford/primesieve-
python

>>> from primesieve import *# Generate a list of the primes below 40>>> generate_primes(40)[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]# Generate a list of the primes between 100 and 120>>> generate_primes(100, 120)[101, 103, 107, 109, 113]# Generate a list of the first 10 primes>>> generate_n_primes(10)[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]# Generate a list of the first 10 starting at 1000>>> generate_n_primes(10, 1000)[1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061]# Get the 10th prime>>> nth_prime(10)29# Count the primes below 10**9>>> count_primes(10**9)50847534


转载请注明:文章转载自 www.wk8.com.cn
本文地址:https://www.wk8.com.cn/it/640029.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 wk8.com.cn

ICP备案号:晋ICP备2021003244-6号