python输出素数的程序_圆素数不正确的输出Python程序

问题陈述 :

数字197被称为圆质数,因为数字的所有旋转:197,971和719本身都是质数.

100以下有13个这样的素数:2、3、5、7、11、13、17、31、37、71、73、79和97.

一百万以下有多少个圆形素数?

我的问题

我检查了所有代码,发现二进制搜索功能给出return 1语句作为输出打印成功.但是什么都没有添加到最终列表中.请帮忙

用Python编写程序:

from time import time

start = time()

LIMIT = 1000000 # largest limit of the prime numbers

prima = [] # list of primes later to be filled by primes function

# binary search function

def Bsearch(lsta,low,high,search):

if low>high:

return -1

else:

mid = int((low+high)/2)

if search

Bsearch(lsta,low,mid-1,search)

elif search>lsta[mid]:

Bsearch(lsta,mid+1,high,search)

elif search==lsta[mid]:

print("Success!")

return 1

# prime number generating function

# uses sieve of Era** algorithm

# produces correct result tested

def primes(LIMIT):

lsta = {} # temporaty empty dictionary

for i in range(2,LIMIT):

lsta[i] = 1

for i in range(2,LIMIT):

for j in range(i,LIMIT):

if i*j>LIMIT:

break

lsta[i*j] = 0

for i in range(2,LIMIT):

if(lsta[i]==1):

prima.append(i)

primes(LIMIT)

final = []

for item in prima:

x = int(str(item)[::-1])

# real problem here the following statement not inserting any value in final list

if(Bsearch(prima,0,len(prima)-1,x)):

print("Hello!")

print(final)

final.append(item)

print(final)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值