素数合计【难度:2级】:
答案1:
from itertools import product
def isPrime(n):
return n==2 or n%2 and all(n%p for p in range(3,int(n**.5)+1,2))
def get_total_primes(a, b):
low, high = map(len, map(str, (a,b)))
return sum( a <= n < b and isPrime(n) for d in range(low,high+1) for n in map(int, map(''.join, product("2357",repeat=d))))
答案2:
from itertools import compress
from bisect import bisect_left
import numpy as np
s = np.ones(10 ** 7 + 2)
s[:2] = s[4::2] = 0
for i in range(3, int(len(s)**0.5)+1, 2):
if s[i]:
s[i*i::i] = 0
DIGIT_PRIMES = frozenset('2357')
total_primes = [x for x in compress(range(len(s)), s) if frozenset(str(x)) <= DIGIT_PRIMES]
def get_total_primes(a, b):
return bisect_left(total_primes, b) - bisect_left(total_primes, a)
答案3:
def prime_below(n):
sieve = n // 2 * [1]
for i in range(3, int(n ** .5) + 1, 2):
if sieve[i // 2]:
sieve[i*i // 2:: i] = ((n - i*i - 1) // (2*i) + 1) * [0]
return [2] + [i for i in range(3, n, 2) if sieve[i // 2]]
total_primes = [n for n in prime_below(10 ** 7) if set(str(n)) <= set('2357')]
from bisect import bisect_left
get_total_primes = lambda a, b: bisect_left(total_primes, b) - bisect_left(total_primes, a)
答案4:
import gmpy2
import itertools
import math
def get_total_primes(a, b):
arr = []
c = 0
for i in range(math.ceil(math.log10(a)),math.ceil(math.log10(b))+1):
arr += list(map("".join, itertools.product('2357',repeat = i)))
for i in arr:
if gmpy2.is_prime(int(i)) and int(i) < b and int(i) >= a:
c += 1
return c
答案5:
import math, re
def is_prime(n):
if n % 2 == 0 and n > 2:
return False
return all(n % i for i in range(3, int(math.sqrt(n)) + 1, 2))
def get_total_primes(a, b):
c = 0
while a < b:
r = re.search('[014689]', str(a)[::-1])
if r:
a += 10**r.start()
a -= a % 10**r.start()
continue
if is_prime(a):
c += is_prime(a)
a += 1
return c
答案6:
def get_total_primes(a, b):
z = [2, 3, 5, 7, 23, 37, 53, 73, 223, 227, 233, 257, 277, 337, 353, 373, 523, 557, 577, 727, 733, 757, 773, 2237, 2273, 2333, 2357, 2377, 2557, 2753, 2777, 3253, 3257, 3323, 3373, 3527, 3533, 3557, 3727, 3733, 5227, 5233, 5237, 5273, 5323, 5333, 5527, 5557, 5573, 5737, 7237, 7253, 7333, 7523, 7537, 7573, 7577, 7723, 7727, 7753, 7757, 22273, 22277, 22573, 22727, 22777, 23227, 23327, 23333, 23357, 23537, 23557, 23753, 23773, 25237, 25253, 25357, 25373, 25523, 25537, 25577, 25733, 27253, 27277, 27337, 27527, 27733, 27737, 27773, 32233, 32237, 32257, 32323, 32327, 32353, 32377, 32533, 32537, 32573, 33223, 33353, 33377, 33533, 33577, 33757, 33773, 35227, 35257, 35323, 35327, 35353, 35527, 35533, 35537, 35573, 35753, 37223, 37253, 37273, 37277, 37337, 37357, 37537, 37573, 52223, 52237, 52253, 52553, 52727, 52733, 52757, 53233, 53323, 53327, 53353, 53377, 53527, 53773, 53777, 55333, 55337, 55373, 55733, 57223, 57373, 57527, 57557, 57727, 57737, 57773, 72223, 72227, 72253, 72277, 72337, 72353, 72533, 72577, 72727, 72733, 73237, 73277, 73327, 73523, 73553, 73727, 73757, 75223, 75227, 75253, 75277, 75323, 75337, 75353, 75377, 75527, 75533, 75553, 75557, 75577, 75773, 77237, 77323, 77377, 77527, 77557, 77573, 77723, 77773, 222323, 222337, 222527, 222533, 222553, 222557, 222773, 223253, 223273, 223277, 223337, 223577, 223753, 223757, 225223, 225227, 225257, 225353, 225373, 225523, 225527, 225733, 227233, 227257, 227377, 227533, 227537, 232333, 232357, 232523, 232753, 232777, 233323, 233327, 233353, 233357, 233557, 233777, 235273, 235337, 235523, 235537, 235553, 235577, 235723, 237233, 237257, 237277, 237373, 237733, 237737, 252223, 252233, 252253, 252277, 252323, 252533, 252727, 252737, 253273, 253537, 253553, 253573, 253733, 253777, 255253, 255523, 255733, 255757, 257273, 257353, 272227, 272257, 272333, 272353, 272533, 272537, 272737, 272777, 273233, 273253, 273323, 273527, 273727, 273773, 275227, 275323, 275357, 275573, 275773, 277223, 277273, 277373, 277577, 277757, 322237, 322327, 322523, 322537, 322573, 322727, 322757, 323233, 323273, 323333, 323377, 323537, 325333, 325537, 325723, 325753, 325777, 327277, 327337, 327553, 327557, 327737, 327757, 332273, 332573, 333227, 333233, 333253, 333323, 333337, 333533, 333737, 333757, 335273, 335323, 335527, 335557, 337223, 337277, 337327, 337537, 352237, 352273, 352327, 352333, 352357, 352523, 352753, 352757, 353237, 353333, 353527, 353557, 353737, 353777, 355573, 355723, 355753, 355777, 357353, 357377, 357727, 357733, 357737, 372223, 372277, 372353, 372377, 372523, 372733, 372773, 373273, 373327, 373357, 373553, 373753, 373757, 373777, 375223, 375227, 375233, 375253, 375257, 375373, 375523, 375527, 375533, 375553, 375757, 375773, 377257, 377327, 377353, 377527, 377537, 377557, 377737, 522227, 522233, 522323, 522337, 522373, 522523, 522553, 522737, 522757, 523333, 523357, 523553, 523573, 523577, 523777, 525253, 525257, 525353, 525373, 525377, 525533, 525727, 525773, 527237, 527273, 527327, 527333, 527353, 527377, 527533, 527557, 527753, 532277, 532327, 532333, 532373, 532523, 532537, 532733, 532757, 533227, 533237, 533257, 533327, 533353, 533573, 533723, 533737, 533777, 535237, 535273, 535333, 535523, 535573, 535727, 535757, 537233, 537373, 537527, 537773, 552353, 552523, 552527, 552553, 552757, 553253, 553277, 553573, 553727, 553733, 553757, 555253, 555257, 555277, 555337, 555523, 555557, 557273, 557377, 557533, 557537, 557573, 572233, 572323, 572333, 572357, 572573, 572777, 573253, 573277, 573523, 573527, 573557, 573737, 573757, 575257, 575557, 575573, 575723, 575753, 575777, 577327, 577333, 577523, 577537, 577573, 577757, 722237, 722257, 722273, 722333, 722353, 722377, 722537, 722723, 722737, 723227, 723257, 723337, 723353, 723553, 723727, 725273, 725323, 725327, 725357, 725537, 725723, 725737, 727273, 727327, 727577, 727733, 727777, 732233, 732257, 732323, 732373, 732533, 733237, 733273, 733277, 733333, 733373, 733753, 733757, 735337, 735373, 735533, 735557, 735733, 737327, 737353, 737533, 737537, 737573, 737753, 737773, 752273, 752527, 753257, 753353, 753373, 753527, 753737, 753773, 755233, 755257, 755273, 755333, 755357, 755737, 757327, 757553, 757577, 757727, 757753, 772273, 772333, 772537, 772573, 772757, 773273, 773533, 773537, 773723, 773777, 775237, 775273, 775553, 775573, 775757, 775777, 777277, 777353, 777373, 777737, 2222273, 2222327, 2222333, 2222377, 2222527, 2222533, 2222537, 2222573, 2222723, 2223233, 2223253, 2223757, 2223773, 2225233, 2225323, 2225533, 2225557, 2225753, 2225777, 2227223, 2227273, 2227327, 2227333, 2227723, 2227727, 2227777, 2232257, 2232323, 2232337, 2232353, 2232523, 2232773, 2233223, 2233337, 2233373, 2233523, 2233537, 2233573, 2233723, 2233753, 2233757, 2235227, 2235257, 2235323, 2235353, 2235377, 2235553, 2235557, 2235733, 2235773, 2237327, 2237527, 2237537, 2237773, 2252233, 2252273, 2252353, 2252557, 2252753, 2253253, 2253257, 2253323, 2253353, 2253557, 2253773, 2255233, 2255257, 2255333, 2255573, 2255723, 2255753, 2257237, 2257373, 2257553, 2257733, 2257757, 2272223, 2272253, 2272273, 2272337, 2272357, 2272537, 2272727, 2272733, 2272757, 2273273, 2273333, 2273357, 2273533, 2275327, 2275333, 2275723, 2275733, 2277377, 2277553, 2277727, 2277733, 2322227, 2322253, 2322337, 2322373, 2322377, 2322577, 2322757, 2323273, 2323337, 2323733, 2323777, 2325227, 2325377, 2325773, 2327233, 2327257, 2327323, 2327527, 2327723, 2327737, 2327753, 2327777, 2332237, 2332327, 2332333, 2332373, 2332523, 2332537, 2333237, 2333323, 2333377, 2333533, 2335253, 2335523, 2335577, 2335733, 2337227, 2337233, 2337527, 2337553, 2337737, 2337773, 2352223, 2352227, 2352323, 2352353, 2352533, 2352557, 2352577, 2353223, 2353577, 2353723, 2355233, 2355253, 2355277, 2355337, 2355377, 2355527, 2355533, 2355557, 2355733, 2357353, 2357357, 2357527, 2357533, 2357573, 2357737, 2372257, 2372327, 2372737, 2372753, 2373227, 2373253, 2373277, 2373323, 2373337, 2373373, 2373533, 2373773, 2375237, 2375273, 2375327, 2375353, 2375557, 2375573, 2375773, 2375777, 2377253, 2377273, 2377357, 2377553, 2377757, 2522227, 2522237, 2522257, 2522357, 2522557, 2522753, 2523223, 2523337, 2523527, 2523533, 2523557, 2523727, 2523757, 2525227, 2525273, 2525323, 2525557, 2525753, 2527223, 2527253, 2527277, 2527537, 2527573, 2527753, 2527757, 2532223, 2532527, 2532727, 2533273, 2533277, 2533373, 2533577, 2533733, 2533753, 2535223, 2535233, 2535353, 2535373, 2535527, 2535553, 2537237, 2537323, 2537527, 2537537, 2552233, 2552357, 2552527, 2552773, 2552777, 2553223, 2553227, 2553233, 2553337, 2553527, 2555227, 2555233, 2555353, 2555753, 2557273, 2557277, 2557333, 2557337, 2557553, 2557757, 2557777, 2572237, 2572327, 2572373, 2572523, 2572777, 2573237, 2573353, 2573357, 2573533, 2573737, 2573777, 2575277, 2575327, 2575337, 2575373, 2575523, 2575537, 2575723, 2575733, 2575753, 2575757, 2575777, 2577733, 2722273, 2722337, 2722553, 2723323, 2723333, 2723353, 2723737, 2725237, 2725337, 2725357, 2725537, 2725553, 2727223, 2727253, 2727577, 2727727, 2727733, 2732237, 2732273, 2732357, 2732537, 2732753, 2733233, 2733253, 2733257, 2733373, 2733733, 2733737, 2735323, 2735357, 2735377, 2735527, 2735723, 2735737, 2737333, 2737523, 2737723, 2737727, 2752223, 2752357, 2752523, 2752723, 2752733, 2753237, 2753323, 2753533, 2753573, 2755223, 2755237, 2757257, 2757323, 2757533, 2757577, 2757773, 2772227, 2772257, 2772533, 2773223, 2773237, 2773273, 2773523, 2775257, 2775277, 2775323, 2775527, 2775733, 2775737, 2777233, 2777353, 2777527, 2777557, 2777573, 3222223, 3222253, 3222337, 3222727, 3222773, 3223223, 3223273, 3223333, 3223357, 3223373, 3223537, 3223757, 3225227, 3225323, 3225373, 3225377, 3225737, 3227353, 3227723, 3232373, 3232553, 3232753, 3232777, 3233227, 3233257, 3233323, 3233327, 3233333, 3233357, 3233533, 3233753, 3233773, 3235223, 3235553, 3235577, 3235723, 3235753, 3235777, 3237233, 3237257, 3237523, 3237527, 3237557, 3252377, 3252523, 3252527, 3252533, 3252577, 3252773, 3253223, 3253253, 3253333, 3253553, 3253753, 3253777, 3255227, 3255233, 3255377, 3255557, 3255773, 3257257, 3257377, 3257533, 3257753, 3257777, 3272323, 3272327, 3272377, 3272527, 3272723, 3273233, 3273323, 3273527, 3273533, 3273737, 3273773, 3275357, 3275537, 3275737, 3277327, 3277777, 3322237, 3322273, 3322337, 3322357, 3322523, 3322537, 3322577, 3322723, 3322727, 3322757, 3323557, 3325237, 3325253, 3325327, 3325373, 3325573, 3325733, 3327227, 3327253, 3327353, 3327377, 3327523, 3327773, 3332233, 3332737, 3333233, 3333257, 3333277, 3333373, 3333527, 3333727, 3333773, 3335257, 3335273, 3335533, 3335537, 3335573, 3335737, 3335753, 3335777, 3337237, 3337333, 3337577, 3337723, 3337757, 3337777, 3352277, 3352373, 3352537, 3353227, 3353237, 3353323, 3353333, 3353533, 3353773, 3355337, 3355357, 3355553, 3355577, 3355733, 3355757, 3355777, 3357223, 3357253, 3357323, 3357337, 3357353, 3357577, 3372227, 3372233, 3372353, 3372727, 3372737, 3372757, 3372773, 3373553, 3373753, 3375233, 3375257, 3375523, 3375577, 3375737, 3377377, 3377557, 3377723, 3522737, 3522773, 3523327, 3523337, 3523357, 3525377, 3525553, 3525727, 3527233, 3527327, 3527527, 3527723, 3532237, 3532253, 3532523, 3532553, 3532733, 3532757, 3533357, 3533377, 3533533, 3533557, 3533573, 3533723, 3535237, 3535253, 3535277, 3535327, 3535373, 3535573, 3535733, 3537277, 3537337, 3537733, 3537773, 3552233, 3552277, 3552533, 3553223, 3553273, 3553327, 3553553, 3553723, 3553777, 3555257, 3555353, 3555557, 3557273, 3557327, 3557377, 3557527, 3557557, 3557737, 3557773, 3572357, 3572377, 3573223, 3573253, 3573337, 3573373, 3573523, 3573527, 3573727, 3573733, 3575333, 3575357, 3575573, 3577253, 3577333, 3577337, 3577573, 3577577, 3577727, 3722273, 3722357, 3723227, 3723233, 3723277, 3723337, 3723773, 3725233, 3725257, 3725357, 3725573, 3725753, 3727723, 3727727, 3727753, 3732373, 3732577, 3732727, 3733273, 3733333, 3733537, 3733757, 3735227, 3735233, 3735253, 3735323, 3735353, 3735377, 3735527, 3735553, 3735737, 3735773, 3737233, 3737323, 3737353, 3737557, 3752237, 3752327, 3752533, 3752773, 3753223, 3753257, 3753353, 3753377, 3753523, 3753553, 3755237, 3755273, 3755333, 3755753, 3757577, 3757723, 3757777, 3772337, 3772537, 3772577, 3772733, 3772753, 3772757, 3773257, 3773327, 3773377, 3773527, 3773573, 3773773, 3775333, 3775553, 3775573, 3775757, 3775777, 3777223, 3777233, 3777253, 3777377, 5222237, 5222323, 5222333, 5222533, 5222573, 5222753, 5223227, 5223377, 5223557, 5223577, 5223773, 5225237, 5225333, 5225377, 5225527, 5225533, 5225537, 5225723, 5225777, 5227253, 5227333, 5227723, 5227727, 5227753, 5227757, 5227777, 5232223, 5232257, 5232323, 5232553, 5232727, 5232737, 5233223, 5233237, 5233523, 5233577, 5233727, 5233777, 5235233, 5235253, 5235323, 5235353, 5235523, 5235553, 5235733, 5235757, 5237227, 5237237, 5237273, 5237327, 5237333, 5237527, 5237723, 5237753, 5252327, 5252333, 5252537, 5252773, 5253277, 5253757, 5255233, 5255357, 5255527, 5255573, 5255773, 5255777, 5257253, 5257277, 5257723, 5257727, 5272237, 5272327, 5272753, 5273227, 5273327, 5273537, 5273753, 5273777, 5275373, 5275537, 5275553, 5275573, 5275577, 5275723, 5275727, 5277227, 5277253, 5277257, 5277527, 5277773, 5322227, 5322253, 5322257, 5322277, 5322323, 5322353, 5322523, 5322533, 5322553, 5323273, 5323277, 5323757, 5323777, 5325223, 5325323, 5325337, 5325527, 5325533, 5325553, 5325737, 5327323, 5327327, 5327527, 5327537, 5327723, 5327737, 5332273, 5332333, 5332553, 5332753, 5333227, 5333233, 5333327, 5333353, 5333533, 5333557, 5335273, 5335723, 5335753, 5335777, 5337373, 5337377, 5337523, 5337533, 5337557, 5337733, 5337737, 5352257, 5352337, 5352533, 5353223, 5353357, 5353553, 5353727, 5353757, 5355257, 5355277, 5355577, 5355733, 5355737, 5357237, 5357353, 5357537, 5357557, 5357777, 5372233, 5372273, 5372333, 5372537, 5372723, 5372753, 5373233, 5373253, 5373527, 5373727, 5373733, 5373737, 5373773, 5375257, 5375273, 5375327, 5375533, 5375753, 5377237, 5377357, 5377373, 5377727, 5522233, 5522273, 5522327, 5522353, 5522527, 5523223, 5523227, 5523257, 5523373, 5523527, 5523773, 5525327, 5525753, 5525777, 5527237, 5527253, 5527573, 5527733, 5532223, 5532227, 5532377, 5532557, 5532577, 5532727, 5532757, 5533223, 5533273, 5533277, 5533337, 5533373, 5533523, 5533537, 5533553, 5533573, 5535223, 5535253, 5535337, 5535377, 5535773, 5537353, 5537377, 5537533, 5537737, 5552233, 5552737, 5552773, 5553227, 5553253, 5553277, 5553337, 5553727, 5553733, 5553773, 5555233, 5555237, 5555323, 5555357, 5555527, 5555723, 5555777, 5557333, 5557523, 5557537, 5557553, 5557723, 5557753, 5557757, 5572253, 5572733, 5573237, 5573257, 5573333, 5573353, 5573357, 5573377, 5573527, 5573573, 5573723, 5575237, 5575277, 5575357, 5575523, 5575553, 5575723, 5575777, 5577223, 5577277, 5577337, 5577527, 5577577, 5577727, 5722273, 5722333, 5722337, 5722373, 5722573, 5722733, 5722757, 5723233, 5723327, 5723737, 5725253, 5725273, 5725333, 5725523, 5725757, 5725777, 5727223, 5727277, 5727377, 5727523, 5732257, 5732273, 5732323, 5732527, 5732537, 5733223, 5733323, 5733337, 5733373, 5733523, 5733527, 5733737, 5733773, 5735357, 5735753, 5737357, 5737757, 5752223, 5752757, 5753273, 5753323, 5753353, 5753533, 5753557, 5753723, 5753777, 5755237, 5755357, 5755577, 5755733, 5755753, 5757223, 5757253, 5757277, 5757523, 5757553, 5757727, 5757733, 5757737, 5772227, 5772233, 5772337, 5772353, 5772527, 5772553, 5772773, 5773373, 5773553, 5773577, 5775337, 5775527, 5775557, 5777227, 5777237, 5777323, 5777353, 5777533, 5777537, 5777557, 5777573, 7222357, 7222373, 7222573, 7222723, 7222757, 7223323, 7223533, 7223537, 7223737, 7223773, 7225277, 7225327, 7225373, 7225723, 7227377, 7227527, 7232227, 7232233, 7232377, 7232527, 7232573, 7232737, 7233257, 7233277, 7233337, 7233377, 7233727, 7233773, 7235237, 7235273, 7235323, 7235533, 7235537, 7235573, 7235737, 7237253, 7237277, 7237333, 7237523, 7237553, 7237723, 7237753, 7237757, 7237777, 7252237, 7252253, 7252327, 7252373, 7252733, 7253333, 7253537, 7253723, 7253773, 7253777, 7255253, 7255357, 7255723, 7255727, 7255733, 7255757, 7257227, 7257253, 7257323, 7257527, 7257553, 7257577, 7257773, 7272227, 7272257, 7272337, 7272373, 7272527, 7272557, 7272737, 7273237, 7273337, 7273723, 7275227, 7275353, 7275377, 7275533, 7275733, 7275757, 7275773, 7277327, 7277533, 7277537, 7277573, 7277723, 7277737, 7322233, 7322537, 7322753, 7323353, 7323377, 7323523, 7323527, 7323557, 7323577, 7323733, 7323737, 7323773, 7325273, 7325333, 7325533, 7325557, 7325723, 7327237, 7327337, 7332257, 7332373, 7332733, 7333253, 7333327, 7333357, 7335257, 7335277, 7335353, 7335533, 7335553, 7335733, 7337227, 7337327, 7337333, 7337357, 7337723, 7337777, 7352273, 7352333, 7352353, 7352537, 7352777, 7353223, 7353233, 7353253, 7353373, 7353377, 7353527, 7353553, 7355233, 7355273, 7355323, 7355533, 7355573, 7355723, 7357223, 7357373, 7357577, 7372357, 7372523, 7372553, 7372753, 7373227, 7373237, 7373357, 7373537, 7373573, 7375223, 7375253, 7375273, 7375573, 7377233, 7377277, 7377373, 7377533, 7377577, 7522327, 7522573, 7523357, 7523533, 7523573, 7523777, 7525333, 7525723, 7525757, 7527253, 7527257, 7527523, 7527577, 7527727, 7532323, 7532527, 7532533, 7532537, 7532573, 7532773, 7533223, 7533377, 7533553, 7533577, 7533727, 7533733, 7535323, 7535527, 7537223, 7537237, 7537253, 7537333, 7537337, 7537373, 7537723, 7552277, 7552327, 7552537, 7552577, 7552723, 7552757, 7553327, 7553333, 7553573, 7553737, 7555333, 7555337, 7557227, 7557373, 7557523, 7557773, 7572223, 7572233, 7572337, 7572373, 7573253, 7573327, 7573537, 7573733, 7575223, 7575233, 7575277, 7575527, 7575577, 7577527, 7577723, 7577753, 7577777, 7722257, 7722277, 7722373, 7722527, 7722557, 7722773, 7723337, 7723357, 7723537, 7723553, 7723733, 7723753, 7723777, 7725323, 7725373, 7725527, 7725733, 7727233, 7727273, 7727323, 7727353, 7727777, 7732327, 7732337, 7732523, 7732553, 7732727, 7733233, 7733357, 7733377, 7733573, 7733723, 7735253, 7735327, 7735333, 7735537, 7735573, 7735577, 7735733, 7737337, 7737557, 7737733, 7752223, 7752253, 7752373, 7752377, 7752557, 7753337, 7753357, 7753523, 7755233, 7755277, 7755323, 7755337, 7755353, 7755773, 7757237, 7757257, 7757353, 7757537, 7757723, 7772333, 7772353, 7772753, 7772773, 7772777, 7773253, 7773257, 7773323, 7773523, 7775323, 7775377, 7775533, 7775737, 7775753, 7777223, 7777337, 7777537, 7777573, 7777727, 7777753]
q = [x for x in z if a <= x < b]
return len(q)
答案7:
import itertools
def make_val(t):
s = 0
for v in t:
s = s * 10 + v
return s
def isprime(n):
if n <= 1: return False
if n == 2 or n == 3: return True
for i in range(5, int(n**0.5+1), 2):
if n % i == 0: return False
return True
primenumbers = [2,3,5,7]
primedigits = [2,3,5,7]
for i in range(2, 8):
for v in itertools.product(primedigits,repeat=i):
if v[-1] == 2 or v[-1] == 5: continue
if sum(v) % 3 == 0: continue
s = make_val(v)
if isprime(s): primenumbers += [s]
def search_index(v):
d, f = 0, len(primenumbers)
while f >= d:
m = (d + f) // 2
if m == len(primenumbers): return m
if primenumbers[m] == v: return m
if v > primenumbers[m]: d = m + 1
else: f = m - 1
return d
def get_total_primes(a, b):
sa = search_index(a)
sb = search_index(b)
return search_index(b)-search_index(a)
答案8:
from gmpy2 import next_prime, is_prime
primes = []
a, b = 2, 10000000
while a<b:
if all(x in (2,3,5,7) for x in map(int, str(a))):
primes.append(a)
a = next_prime(a)
def get_total_primes(a, b):
return len(list(filter(lambda n: n>=a and n<b, primes)))
答案9:
primes = [2, 3, 5, 7, 23, 37, 53, 73, 223, 227, 233, 257, 277, 337, 353, 373, 523, 557, 577, 727, 733, 757, 773, 2237, 2273, 2333, 2357, 2377, 2557, 2753, 2777, 3253, 3257, 3323, 3373, 3527, 3533, 3557, 3727, 3733, 5227, 5233, 5237, 5273, 5323, 5333, 5527, 5557, 5573, 5737, 7237, 7253, 7333, 7523, 7537, 7573, 7577, 7723, 7727, 7753, 7757, 22273, 22277, 22573, 22727, 22777, 23227, 23327, 23333, 23357, 23537, 23557, 23753, 23773, 25237, 25253, 25357, 25373, 25523, 25537, 25577, 25733, 27253, 27277, 27337, 27527, 27733, 27737, 27773, 32233, 32237, 32257, 32323, 32327, 32353, 32377, 32533, 32537, 32573, 33223, 33353, 33377, 33533, 33577, 33757, 33773, 35227, 35257, 35323, 35327, 35353, 35527, 35533, 35537, 35573, 35753, 37223, 37253, 37273, 37277, 37337, 37357, 37537, 37573, 52223, 52237, 52253, 52553, 52727, 52733, 52757, 53233, 53323, 53327, 53353, 53377, 53527, 53773, 53777, 55333, 55337, 55373, 55733, 57223, 57373, 57527, 57557, 57727, 57737, 57773, 72223, 72227, 72253, 72277, 72337, 72353, 72533, 72577, 72727, 72733, 73237, 73277, 73327, 73523, 73553, 73727, 73757, 75223, 75227, 75253, 75277, 75323, 75337, 75353, 75377, 75527, 75533, 75553, 75557, 75577, 75773, 77237, 77323, 77377, 77527, 77557, 77573, 77723, 77773, 222323, 222337, 222527, 222533, 222553, 222557, 222773, 223253, 223273, 223277, 223337, 223577, 223753, 223757, 225223, 225227, 225257, 225353, 225373, 225523, 225527, 225733, 227233, 227257, 227377, 227533, 227537, 232333, 232357, 232523, 232753, 232777, 233323, 233327, 233353, 233357, 233557, 233777, 235273, 235337, 235523, 235537, 235553, 235577, 235723, 237233, 237257, 237277, 237373, 237733, 237737, 252223, 252233, 252253, 252277, 252323, 252533, 252727, 252737, 253273, 253537, 253553, 253573, 253733, 253777, 255253, 255523, 255733, 255757, 257273, 257353, 272227, 272257, 272333, 272353, 272533, 272537, 272737, 272777, 273233, 273253, 273323, 273527, 273727, 273773, 275227, 275323, 275357, 275573, 275773, 277223, 277273, 277373, 277577, 277757, 322237, 322327, 322523, 322537, 322573, 322727, 322757, 323233, 323273, 323333, 323377, 323537, 325333, 325537, 325723, 325753, 325777, 327277, 327337, 327553, 327557, 327737, 327757, 332273, 332573, 333227, 333233, 333253, 333323, 333337, 333533, 333737, 333757, 335273, 335323, 335527, 335557, 337223, 337277, 337327, 337537, 352237, 352273, 352327, 352333, 352357, 352523, 352753, 352757, 353237, 353333, 353527, 353557, 353737, 353777, 355573, 355723, 355753, 355777, 357353, 357377, 357727, 357733, 357737, 372223, 372277, 372353, 372377, 372523, 372733, 372773, 373273, 373327, 373357, 373553, 373753, 373757, 373777, 375223, 375227, 375233, 375253, 375257, 375373, 375523, 375527, 375533, 375553, 375757, 375773, 377257, 377327, 377353, 377527, 377537, 377557, 377737, 522227, 522233, 522323, 522337, 522373, 522523, 522553, 522737, 522757, 523333, 523357, 523553, 523573, 523577, 523777, 525253, 525257, 525353, 525373, 525377, 525533, 525727, 525773, 527237, 527273, 527327, 527333, 527353, 527377, 527533, 527557, 527753, 532277, 532327, 532333, 532373, 532523, 532537, 532733, 532757, 533227, 533237, 533257, 533327, 533353, 533573, 533723, 533737, 533777, 535237, 535273, 535333, 535523, 535573, 535727, 535757, 537233, 537373, 537527, 537773, 552353, 552523, 552527, 552553, 552757, 553253, 553277, 553573, 553727, 553733, 553757, 555253, 555257, 555277, 555337, 555523, 555557, 557273, 557377, 557533, 557537, 557573, 572233, 572323, 572333, 572357, 572573, 572777, 573253, 573277, 573523, 573527, 573557, 573737, 573757, 575257, 575557, 575573, 575723, 575753, 575777, 577327, 577333, 577523, 577537, 577573, 577757, 722237, 722257, 722273, 722333, 722353, 722377, 722537, 722723, 722737, 723227, 723257, 723337, 723353, 723553, 723727, 725273, 725323, 725327, 725357, 725537, 725723, 725737, 727273, 727327, 727577, 727733, 727777, 732233, 732257, 732323, 732373, 732533, 733237, 733273, 733277, 733333, 733373, 733753, 733757, 735337, 735373, 735533, 735557, 735733, 737327, 737353, 737533, 737537, 737573, 737753, 737773, 752273, 752527, 753257, 753353, 753373, 753527, 753737, 753773, 755233, 755257, 755273, 755333, 755357, 755737, 757327, 757553, 757577, 757727, 757753, 772273, 772333, 772537, 772573, 772757, 773273, 773533, 773537, 773723, 773777, 775237, 775273, 775553, 775573, 775757, 775777, 777277, 777353, 777373, 777737, 2222273, 2222327, 2222333, 2222377, 2222527, 2222533, 2222537, 2222573, 2222723, 2223233, 2223253, 2223757, 2223773, 2225233, 2225323, 2225533, 2225557, 2225753, 2225777, 2227223, 2227273, 2227327, 2227333, 2227723, 2227727, 2227777, 2232257, 2232323, 2232337, 2232353, 2232523, 2232773, 2233223, 2233337, 2233373, 2233523, 2233537, 2233573, 2233723, 2233753, 2233757, 2235227, 2235257, 2235323, 2235353, 2235377, 2235553, 2235557, 2235733, 2235773, 2237327, 2237527, 2237537, 2237773, 2252233, 2252273, 2252353, 2252557, 2252753, 2253253, 2253257, 2253323, 2253353, 2253557, 2253773, 2255233, 2255257, 2255333, 2255573, 2255723, 2255753, 2257237, 2257373, 2257553, 2257733, 2257757, 2272223, 2272253, 2272273, 2272337, 2272357, 2272537, 2272727, 2272733, 2272757, 2273273, 2273333, 2273357, 2273533, 2275327, 2275333, 2275723, 2275733, 2277377, 2277553, 2277727, 2277733, 2322227, 2322253, 2322337, 2322373, 2322377, 2322577, 2322757, 2323273, 2323337, 2323733, 2323777, 2325227, 2325377, 2325773, 2327233, 2327257, 2327323, 2327527, 2327723, 2327737, 2327753, 2327777, 2332237, 2332327, 2332333, 2332373, 2332523, 2332537, 2333237, 2333323, 2333377, 2333533, 2335253, 2335523, 2335577, 2335733, 2337227, 2337233, 2337527, 2337553, 2337737, 2337773, 2352223, 2352227, 2352323, 2352353, 2352533, 2352557, 2352577, 2353223, 2353577, 2353723, 2355233, 2355253, 2355277, 2355337, 2355377, 2355527, 2355533, 2355557, 2355733, 2357353, 2357357, 2357527, 2357533, 2357573, 2357737, 2372257, 2372327, 2372737, 2372753, 2373227, 2373253, 2373277, 2373323, 2373337, 2373373, 2373533, 2373773, 2375237, 2375273, 2375327, 2375353, 2375557, 2375573, 2375773, 2375777, 2377253, 2377273, 2377357, 2377553, 2377757, 2522227, 2522237, 2522257, 2522357, 2522557, 2522753, 2523223, 2523337, 2523527, 2523533, 2523557, 2523727, 2523757, 2525227, 2525273, 2525323, 2525557, 2525753, 2527223, 2527253, 2527277, 2527537, 2527573, 2527753, 2527757, 2532223, 2532527, 2532727, 2533273, 2533277, 2533373, 2533577, 2533733, 2533753, 2535223, 2535233, 2535353, 2535373, 2535527, 2535553, 2537237, 2537323, 2537527, 2537537, 2552233, 2552357, 2552527, 2552773, 2552777, 2553223, 2553227, 2553233, 2553337, 2553527, 2555227, 2555233, 2555353, 2555753, 2557273, 2557277, 2557333, 2557337, 2557553, 2557757, 2557777, 2572237, 2572327, 2572373, 2572523, 2572777, 2573237, 2573353, 2573357, 2573533, 2573737, 2573777, 2575277, 2575327, 2575337, 2575373, 2575523, 2575537, 2575723, 2575733, 2575753, 2575757, 2575777, 2577733, 2722273, 2722337, 2722553, 2723323, 2723333, 2723353, 2723737, 2725237, 2725337, 2725357, 2725537, 2725553, 2727223, 2727253, 2727577, 2727727, 2727733, 2732237, 2732273, 2732357, 2732537, 2732753, 2733233, 2733253, 2733257, 2733373, 2733733, 2733737, 2735323, 2735357, 2735377, 2735527, 2735723, 2735737, 2737333, 2737523, 2737723, 2737727, 2752223, 2752357, 2752523, 2752723, 2752733, 2753237, 2753323, 2753533, 2753573, 2755223, 2755237, 2757257, 2757323, 2757533, 2757577, 2757773, 2772227, 2772257, 2772533, 2773223, 2773237, 2773273, 2773523, 2775257, 2775277, 2775323, 2775527, 2775733, 2775737, 2777233, 2777353, 2777527, 2777557, 2777573, 3222223, 3222253, 3222337, 3222727, 3222773, 3223223, 3223273, 3223333, 3223357, 3223373, 3223537, 3223757, 3225227, 3225323, 3225373, 3225377, 3225737, 3227353, 3227723, 3232373, 3232553, 3232753, 3232777, 3233227, 3233257, 3233323, 3233327, 3233333, 3233357, 3233533, 3233753, 3233773, 3235223, 3235553, 3235577, 3235723, 3235753, 3235777, 3237233, 3237257, 3237523, 3237527, 3237557, 3252377, 3252523, 3252527, 3252533, 3252577, 3252773, 3253223, 3253253, 3253333, 3253553, 3253753, 3253777, 3255227, 3255233, 3255377, 3255557, 3255773, 3257257, 3257377, 3257533, 3257753, 3257777, 3272323, 3272327, 3272377, 3272527, 3272723, 3273233, 3273323, 3273527, 3273533, 3273737, 3273773, 3275357, 3275537, 3275737, 3277327, 3277777, 3322237, 3322273, 3322337, 3322357, 3322523, 3322537, 3322577, 3322723, 3322727, 3322757, 3323557, 3325237, 3325253, 3325327, 3325373, 3325573, 3325733, 3327227, 3327253, 3327353, 3327377, 3327523, 3327773, 3332233, 3332737, 3333233, 3333257, 3333277, 3333373, 3333527, 3333727, 3333773, 3335257, 3335273, 3335533, 3335537, 3335573, 3335737, 3335753, 3335777, 3337237, 3337333, 3337577, 3337723, 3337757, 3337777, 3352277, 3352373, 3352537, 3353227, 3353237, 3353323, 3353333, 3353533, 3353773, 3355337, 3355357, 3355553, 3355577, 3355733, 3355757, 3355777, 3357223, 3357253, 3357323, 3357337, 3357353, 3357577, 3372227, 3372233, 3372353, 3372727, 3372737, 3372757, 3372773, 3373553, 3373753, 3375233, 3375257, 3375523, 3375577, 3375737, 3377377, 3377557, 3377723, 3522737, 3522773, 3523327, 3523337, 3523357, 3525377, 3525553, 3525727, 3527233, 3527327, 3527527, 3527723, 3532237, 3532253, 3532523, 3532553, 3532733, 3532757, 3533357, 3533377, 3533533, 3533557, 3533573, 3533723, 3535237, 3535253, 3535277, 3535327, 3535373, 3535573, 3535733, 3537277, 3537337, 3537733, 3537773, 3552233, 3552277, 3552533, 3553223, 3553273, 3553327, 3553553, 3553723, 3553777, 3555257, 3555353, 3555557, 3557273, 3557327, 3557377, 3557527, 3557557, 3557737, 3557773, 3572357, 3572377, 3573223, 3573253, 3573337, 3573373, 3573523, 3573527, 3573727, 3573733, 3575333, 3575357, 3575573, 3577253, 3577333, 3577337, 3577573, 3577577, 3577727, 3722273, 3722357, 3723227, 3723233, 3723277, 3723337, 3723773, 3725233, 3725257, 3725357, 3725573, 3725753, 3727723, 3727727, 3727753, 3732373, 3732577, 3732727, 3733273, 3733333, 3733537, 3733757, 3735227, 3735233, 3735253, 3735323, 3735353, 3735377, 3735527, 3735553, 3735737, 3735773, 3737233, 3737323, 3737353, 3737557, 3752237, 3752327, 3752533, 3752773, 3753223, 3753257, 3753353, 3753377, 3753523, 3753553, 3755237, 3755273, 3755333, 3755753, 3757577, 3757723, 3757777, 3772337, 3772537, 3772577, 3772733, 3772753, 3772757, 3773257, 3773327, 3773377, 3773527, 3773573, 3773773, 3775333, 3775553, 3775573, 3775757, 3775777, 3777223, 3777233, 3777253, 3777377, 5222237, 5222323, 5222333, 5222533, 5222573, 5222753, 5223227, 5223377, 5223557, 5223577, 5223773, 5225237, 5225333, 5225377, 5225527, 5225533, 5225537, 5225723, 5225777, 5227253, 5227333, 5227723, 5227727, 5227753, 5227757, 5227777, 5232223, 5232257, 5232323, 5232553, 5232727, 5232737, 5233223, 5233237, 5233523, 5233577, 5233727, 5233777, 5235233, 5235253, 5235323, 5235353, 5235523, 5235553, 5235733, 5235757, 5237227, 5237237, 5237273, 5237327, 5237333, 5237527, 5237723, 5237753, 5252327, 5252333, 5252537, 5252773, 5253277, 5253757, 5255233, 5255357, 5255527, 5255573, 5255773, 5255777, 5257253, 5257277, 5257723, 5257727, 5272237, 5272327, 5272753, 5273227, 5273327, 5273537, 5273753, 5273777, 5275373, 5275537, 5275553, 5275573, 5275577, 5275723, 5275727, 5277227, 5277253, 5277257, 5277527, 5277773, 5322227, 5322253, 5322257, 5322277, 5322323, 5322353, 5322523, 5322533, 5322553, 5323273, 5323277, 5323757, 5323777, 5325223, 5325323, 5325337, 5325527, 5325533, 5325553, 5325737, 5327323, 5327327, 5327527, 5327537, 5327723, 5327737, 5332273, 5332333, 5332553, 5332753, 5333227, 5333233, 5333327, 5333353, 5333533, 5333557, 5335273, 5335723, 5335753, 5335777, 5337373, 5337377, 5337523, 5337533, 5337557, 5337733, 5337737, 5352257, 5352337, 5352533, 5353223, 5353357, 5353553, 5353727, 5353757, 5355257, 5355277, 5355577, 5355733, 5355737, 5357237, 5357353, 5357537, 5357557, 5357777, 5372233, 5372273, 5372333, 5372537, 5372723, 5372753, 5373233, 5373253, 5373527, 5373727, 5373733, 5373737, 5373773, 5375257, 5375273, 5375327, 5375533, 5375753, 5377237, 5377357, 5377373, 5377727, 5522233, 5522273, 5522327, 5522353, 5522527, 5523223, 5523227, 5523257, 5523373, 5523527, 5523773, 5525327, 5525753, 5525777, 5527237, 5527253, 5527573, 5527733, 5532223, 5532227, 5532377, 5532557, 5532577, 5532727, 5532757, 5533223, 5533273, 5533277, 5533337, 5533373, 5533523, 5533537, 5533553, 5533573, 5535223, 5535253, 5535337, 5535377, 5535773, 5537353, 5537377, 5537533, 5537737, 5552233, 5552737, 5552773, 5553227, 5553253, 5553277, 5553337, 5553727, 5553733, 5553773, 5555233, 5555237, 5555323, 5555357, 5555527, 5555723, 5555777, 5557333, 5557523, 5557537, 5557553, 5557723, 5557753, 5557757, 5572253, 5572733, 5573237, 5573257, 5573333, 5573353, 5573357, 5573377, 5573527, 5573573, 5573723, 5575237, 5575277, 5575357, 5575523, 5575553, 5575723, 5575777, 5577223, 5577277, 5577337, 5577527, 5577577, 5577727, 5722273, 5722333, 5722337, 5722373, 5722573, 5722733, 5722757, 5723233, 5723327, 5723737, 5725253, 5725273, 5725333, 5725523, 5725757, 5725777, 5727223, 5727277, 5727377, 5727523, 5732257, 5732273, 5732323, 5732527, 5732537, 5733223, 5733323, 5733337, 5733373, 5733523, 5733527, 5733737, 5733773, 5735357, 5735753, 5737357, 5737757, 5752223, 5752757, 5753273, 5753323, 5753353, 5753533, 5753557, 5753723, 5753777, 5755237, 5755357, 5755577, 5755733, 5755753, 5757223, 5757253, 5757277, 5757523, 5757553, 5757727, 5757733, 5757737, 5772227, 5772233, 5772337, 5772353, 5772527, 5772553, 5772773, 5773373, 5773553, 5773577, 5775337, 5775527, 5775557, 5777227, 5777237, 5777323, 5777353, 5777533, 5777537, 5777557, 5777573, 7222357, 7222373, 7222573, 7222723, 7222757, 7223323, 7223533, 7223537, 7223737, 7223773, 7225277, 7225327, 7225373, 7225723, 7227377, 7227527, 7232227, 7232233, 7232377, 7232527, 7232573, 7232737, 7233257, 7233277, 7233337, 7233377, 7233727, 7233773, 7235237, 7235273, 7235323, 7235533, 7235537, 7235573, 7235737, 7237253, 7237277, 7237333, 7237523, 7237553, 7237723, 7237753, 7237757, 7237777, 7252237, 7252253, 7252327, 7252373, 7252733, 7253333, 7253537, 7253723, 7253773, 7253777, 7255253, 7255357, 7255723, 7255727, 7255733, 7255757, 7257227, 7257253, 7257323, 7257527, 7257553, 7257577, 7257773, 7272227, 7272257, 7272337, 7272373, 7272527, 7272557, 7272737, 7273237, 7273337, 7273723, 7275227, 7275353, 7275377, 7275533, 7275733, 7275757, 7275773, 7277327, 7277533, 7277537, 7277573, 7277723, 7277737, 7322233, 7322537, 7322753, 7323353, 7323377, 7323523, 7323527, 7323557, 7323577, 7323733, 7323737, 7323773, 7325273, 7325333, 7325533, 7325557, 7325723, 7327237, 7327337, 7332257, 7332373, 7332733, 7333253, 7333327, 7333357, 7335257, 7335277, 7335353, 7335533, 7335553, 7335733, 7337227, 7337327, 7337333, 7337357, 7337723, 7337777, 7352273, 7352333, 7352353, 7352537, 7352777, 7353223, 7353233, 7353253, 7353373, 7353377, 7353527, 7353553, 7355233, 7355273, 7355323, 7355533, 7355573, 7355723, 7357223, 7357373, 7357577, 7372357, 7372523, 7372553, 7372753, 7373227, 7373237, 7373357, 7373537, 7373573, 7375223, 7375253, 7375273, 7375573, 7377233, 7377277, 7377373, 7377533, 7377577, 7522327, 7522573, 7523357, 7523533, 7523573, 7523777, 7525333, 7525723, 7525757, 7527253, 7527257, 7527523, 7527577, 7527727, 7532323, 7532527, 7532533, 7532537, 7532573, 7532773, 7533223, 7533377, 7533553, 7533577, 7533727, 7533733, 7535323, 7535527, 7537223, 7537237, 7537253, 7537333, 7537337, 7537373, 7537723, 7552277, 7552327, 7552537, 7552577, 7552723, 7552757, 7553327, 7553333, 7553573, 7553737, 7555333, 7555337, 7557227, 7557373, 7557523, 7557773, 7572223, 7572233, 7572337, 7572373, 7573253, 7573327, 7573537, 7573733, 7575223, 7575233, 7575277, 7575527, 7575577, 7577527, 7577723, 7577753, 7577777, 7722257, 7722277, 7722373, 7722527, 7722557, 7722773, 7723337, 7723357, 7723537, 7723553, 7723733, 7723753, 7723777, 7725323, 7725373, 7725527, 7725733, 7727233, 7727273, 7727323, 7727353, 7727777, 7732327, 7732337, 7732523, 7732553, 7732727, 7733233, 7733357, 7733377, 7733573, 7733723, 7735253, 7735327, 7735333, 7735537, 7735573, 7735577, 7735733, 7737337, 7737557, 7737733, 7752223, 7752253, 7752373, 7752377, 7752557, 7753337, 7753357, 7753523, 7755233, 7755277, 7755323, 7755337, 7755353, 7755773, 7757237, 7757257, 7757353, 7757537, 7757723, 7772333, 7772353, 7772753, 7772773, 7772777, 7773253, 7773257, 7773323, 7773523, 7775323, 7775377, 7775533, 7775737, 7775753, 7777223, 7777337, 7777537, 7777573, 7777727, 7777753]
def xbinsearch(pred, lst, *extras, type = "min", default = None):
low, hi, best = 0, len(lst)-1, default
while low <= hi:
mid = (low+hi)//2
p = pred(mid, lst, *extras)
if p[0]:
if type == "min":
if best == default or lst[mid] < lst[best]: best = mid
hi = mid-1
elif type == "max":
if best == default or lst[mid] > lst[best]: best = mid
low = mid+1
elif p[1] == 1:
hi = mid - 1
elif p[1] == -1:
low = mid + 1
return best
def pred_a(idx, lst, *extras):
tpl, val = [None, None], lst[idx],
if extras: a, b = extras[0], extras[1]
tpl[0] = a <= val < b
if val >= b: tpl[1] = 1
elif val < a: tpl[1] = -1
return tuple(tpl)
def get_total_primes(a, b):
low, hi = xbinsearch(pred_a, primes, a, b, default=1), xbinsearch(pred_a, primes, a, b, type="max", default=0)
return hi + 1 - low
答案10:
primes = [2, 3, 5, 7, 23, 37, 53, 73, 223, 227, 233, 257, 277, 337, 353, 373, 523, 557, 577, 727, 733, 757, 773, 2237, 2273, 2333, 2357, 2377, 2557, 2753, 2777, 3253, 3257, 3323, 3373, 3527, 3533, 3557, 3727, 3733, 5227, 5233, 5237, 5273, 5323, 5333, 5527, 5557, 5573, 5737, 7237, 7253, 7333, 7523, 7537, 7573, 7577, 7723, 7727, 7753, 7757, 22273, 22277, 22573, 22727, 22777, 23227, 23327, 23333, 23357, 23537, 23557, 23753, 23773, 25237, 25253, 25357, 25373, 25523, 25537, 25577, 25733, 27253, 27277, 27337, 27527, 27733, 27737, 27773, 32233, 32237, 32257, 32323, 32327, 32353, 32377, 32533, 32537, 32573, 33223, 33353, 33377, 33533, 33577, 33757, 33773, 35227, 35257, 35323, 35327, 35353, 35527, 35533, 35537, 35573, 35753, 37223, 37253, 37273, 37277, 37337, 37357, 37537, 37573, 52223, 52237, 52253, 52553, 52727, 52733, 52757, 53233, 53323, 53327, 53353, 53377, 53527, 53773, 53777, 55333, 55337, 55373, 55733, 57223, 57373, 57527, 57557, 57727, 57737, 57773, 72223, 72227, 72253, 72277, 72337, 72353, 72533, 72577, 72727, 72733, 73237, 73277, 73327, 73523, 73553, 73727, 73757, 75223, 75227, 75253, 75277, 75323, 75337, 75353, 75377, 75527, 75533, 75553, 75557, 75577, 75773, 77237, 77323, 77377, 77527, 77557, 77573, 77723, 77773, 222323, 222337, 222527, 222533, 222553, 222557, 222773, 223253, 223273, 223277, 223337, 223577, 223753, 223757, 225223, 225227, 225257, 225353, 225373, 225523, 225527, 225733, 227233, 227257, 227377, 227533, 227537, 232333, 232357, 232523, 232753, 232777, 233323, 233327, 233353, 233357, 233557, 233777, 235273, 235337, 235523, 235537, 235553, 235577, 235723, 237233, 237257, 237277, 237373, 237733, 237737, 252223, 252233, 252253, 252277, 252323, 252533, 252727, 252737, 253273, 253537, 253553, 253573, 253733, 253777, 255253, 255523, 255733, 255757, 257273, 257353, 272227, 272257, 272333, 272353, 272533, 272537, 272737, 272777, 273233, 273253, 273323, 273527, 273727, 273773, 275227, 275323, 275357, 275573, 275773, 277223, 277273, 277373, 277577, 277757, 322237, 322327, 322523, 322537, 322573, 322727, 322757, 323233, 323273, 323333, 323377, 323537, 325333, 325537, 325723, 325753, 325777, 327277, 327337, 327553, 327557, 327737, 327757, 332273, 332573, 333227, 333233, 333253, 333323, 333337, 333533, 333737, 333757, 335273, 335323, 335527, 335557, 337223, 337277, 337327, 337537, 352237, 352273, 352327, 352333, 352357, 352523, 352753, 352757, 353237, 353333, 353527, 353557, 353737, 353777, 355573, 355723, 355753, 355777, 357353, 357377, 357727, 357733, 357737, 372223, 372277, 372353, 372377, 372523, 372733, 372773, 373273, 373327, 373357, 373553, 373753, 373757, 373777, 375223, 375227, 375233, 375253, 375257, 375373, 375523, 375527, 375533, 375553, 375757, 375773, 377257, 377327, 377353, 377527, 377537, 377557, 377737, 522227, 522233, 522323, 522337, 522373, 522523, 522553, 522737, 522757, 523333, 523357, 523553, 523573, 523577, 523777, 525253, 525257, 525353, 525373, 525377, 525533, 525727, 525773, 527237, 527273, 527327, 527333, 527353, 527377, 527533, 527557, 527753, 532277, 532327, 532333, 532373, 532523, 532537, 532733, 532757, 533227, 533237, 533257, 533327, 533353, 533573, 533723, 533737, 533777, 535237, 535273, 535333, 535523, 535573, 535727, 535757, 537233, 537373, 537527, 537773, 552353, 552523, 552527, 552553, 552757, 553253, 553277, 553573, 553727, 553733, 553757, 555253, 555257, 555277, 555337, 555523, 555557, 557273, 557377, 557533, 557537, 557573, 572233, 572323, 572333, 572357, 572573, 572777, 573253, 573277, 573523, 573527, 573557, 573737, 573757, 575257, 575557, 575573, 575723, 575753, 575777, 577327, 577333, 577523, 577537, 577573, 577757, 722237, 722257, 722273, 722333, 722353, 722377, 722537, 722723, 722737, 723227, 723257, 723337, 723353, 723553, 723727, 725273, 725323, 725327, 725357, 725537, 725723, 725737, 727273, 727327, 727577, 727733, 727777, 732233, 732257, 732323, 732373, 732533, 733237, 733273, 733277, 733333, 733373, 733753, 733757, 735337, 735373, 735533, 735557, 735733, 737327, 737353, 737533, 737537, 737573, 737753, 737773, 752273, 752527, 753257, 753353, 753373, 753527, 753737, 753773, 755233, 755257, 755273, 755333, 755357, 755737, 757327, 757553, 757577, 757727, 757753, 772273, 772333, 772537, 772573, 772757, 773273, 773533, 773537, 773723, 773777, 775237, 775273, 775553, 775573, 775757, 775777, 777277, 777353, 777373, 777737, 2222273, 2222327, 2222333, 2222377, 2222527, 2222533, 2222537, 2222573, 2222723, 2223233, 2223253, 2223757, 2223773, 2225233, 2225323, 2225533, 2225557, 2225753, 2225777, 2227223, 2227273, 2227327, 2227333, 2227723, 2227727, 2227777, 2232257, 2232323, 2232337, 2232353, 2232523, 2232773, 2233223, 2233337, 2233373, 2233523, 2233537, 2233573, 2233723, 2233753, 2233757, 2235227, 2235257, 2235323, 2235353, 2235377, 2235553, 2235557, 2235733, 2235773, 2237327, 2237527, 2237537, 2237773, 2252233, 2252273, 2252353, 2252557, 2252753, 2253253, 2253257, 2253323, 2253353, 2253557, 2253773, 2255233, 2255257, 2255333, 2255573, 2255723, 2255753, 2257237, 2257373, 2257553, 2257733, 2257757, 2272223, 2272253, 2272273, 2272337, 2272357, 2272537, 2272727, 2272733, 2272757, 2273273, 2273333, 2273357, 2273533, 2275327, 2275333, 2275723, 2275733, 2277377, 2277553, 2277727, 2277733, 2322227, 2322253, 2322337, 2322373, 2322377, 2322577, 2322757, 2323273, 2323337, 2323733, 2323777, 2325227, 2325377, 2325773, 2327233, 2327257, 2327323, 2327527, 2327723, 2327737, 2327753, 2327777, 2332237, 2332327, 2332333, 2332373, 2332523, 2332537, 2333237, 2333323, 2333377, 2333533, 2335253, 2335523, 2335577, 2335733, 2337227, 2337233, 2337527, 2337553, 2337737, 2337773, 2352223, 2352227, 2352323, 2352353, 2352533, 2352557, 2352577, 2353223, 2353577, 2353723, 2355233, 2355253, 2355277, 2355337, 2355377, 2355527, 2355533, 2355557, 2355733, 2357353, 2357357, 2357527, 2357533, 2357573, 2357737, 2372257, 2372327, 2372737, 2372753, 2373227, 2373253, 2373277, 2373323, 2373337, 2373373, 2373533, 2373773, 2375237, 2375273, 2375327, 2375353, 2375557, 2375573, 2375773, 2375777, 2377253, 2377273, 2377357, 2377553, 2377757, 2522227, 2522237, 2522257, 2522357, 2522557, 2522753, 2523223, 2523337, 2523527, 2523533, 2523557, 2523727, 2523757, 2525227, 2525273, 2525323, 2525557, 2525753, 2527223, 2527253, 2527277, 2527537, 2527573, 2527753, 2527757, 2532223, 2532527, 2532727, 2533273, 2533277, 2533373, 2533577, 2533733, 2533753, 2535223, 2535233, 2535353, 2535373, 2535527, 2535553, 2537237, 2537323, 2537527, 2537537, 2552233, 2552357, 2552527, 2552773, 2552777, 2553223, 2553227, 2553233, 2553337, 2553527, 2555227, 2555233, 2555353, 2555753, 2557273, 2557277, 2557333, 2557337, 2557553, 2557757, 2557777, 2572237, 2572327, 2572373, 2572523, 2572777, 2573237, 2573353, 2573357, 2573533, 2573737, 2573777, 2575277, 2575327, 2575337, 2575373, 2575523, 2575537, 2575723, 2575733, 2575753, 2575757, 2575777, 2577733, 2722273, 2722337, 2722553, 2723323, 2723333, 2723353, 2723737, 2725237, 2725337, 2725357, 2725537, 2725553, 2727223, 2727253, 2727577, 2727727, 2727733, 2732237, 2732273, 2732357, 2732537, 2732753, 2733233, 2733253, 2733257, 2733373, 2733733, 2733737, 2735323, 2735357, 2735377, 2735527, 2735723, 2735737, 2737333, 2737523, 2737723, 2737727, 2752223, 2752357, 2752523, 2752723, 2752733, 2753237, 2753323, 2753533, 2753573, 2755223, 2755237, 2757257, 2757323, 2757533, 2757577, 2757773, 2772227, 2772257, 2772533, 2773223, 2773237, 2773273, 2773523, 2775257, 2775277, 2775323, 2775527, 2775733, 2775737, 2777233, 2777353, 2777527, 2777557, 2777573, 3222223, 3222253, 3222337, 3222727, 3222773, 3223223, 3223273, 3223333, 3223357, 3223373, 3223537, 3223757, 3225227, 3225323, 3225373, 3225377, 3225737, 3227353, 3227723, 3232373, 3232553, 3232753, 3232777, 3233227, 3233257, 3233323, 3233327, 3233333, 3233357, 3233533, 3233753, 3233773, 3235223, 3235553, 3235577, 3235723, 3235753, 3235777, 3237233, 3237257, 3237523, 3237527, 3237557, 3252377, 3252523, 3252527, 3252533, 3252577, 3252773, 3253223, 3253253, 3253333, 3253553, 3253753, 3253777, 3255227, 3255233, 3255377, 3255557, 3255773, 3257257, 3257377, 3257533, 3257753, 3257777, 3272323, 3272327, 3272377, 3272527, 3272723, 3273233, 3273323, 3273527, 3273533, 3273737, 3273773, 3275357, 3275537, 3275737, 3277327, 3277777, 3322237, 3322273, 3322337, 3322357, 3322523, 3322537, 3322577, 3322723, 3322727, 3322757, 3323557, 3325237, 3325253, 3325327, 3325373, 3325573, 3325733, 3327227, 3327253, 3327353, 3327377, 3327523, 3327773, 3332233, 3332737, 3333233, 3333257, 3333277, 3333373, 3333527, 3333727, 3333773, 3335257, 3335273, 3335533, 3335537, 3335573, 3335737, 3335753, 3335777, 3337237, 3337333, 3337577, 3337723, 3337757, 3337777, 3352277, 3352373, 3352537, 3353227, 3353237, 3353323, 3353333, 3353533, 3353773, 3355337, 3355357, 3355553, 3355577, 3355733, 3355757, 3355777, 3357223, 3357253, 3357323, 3357337, 3357353, 3357577, 3372227, 3372233, 3372353, 3372727, 3372737, 3372757, 3372773, 3373553, 3373753, 3375233, 3375257, 3375523, 3375577, 3375737, 3377377, 3377557, 3377723, 3522737, 3522773, 3523327, 3523337, 3523357, 3525377, 3525553, 3525727, 3527233, 3527327, 3527527, 3527723, 3532237, 3532253, 3532523, 3532553, 3532733, 3532757, 3533357, 3533377, 3533533, 3533557, 3533573, 3533723, 3535237, 3535253, 3535277, 3535327, 3535373, 3535573, 3535733, 3537277, 3537337, 3537733, 3537773, 3552233, 3552277, 3552533, 3553223, 3553273, 3553327, 3553553, 3553723, 3553777, 3555257, 3555353, 3555557, 3557273, 3557327, 3557377, 3557527, 3557557, 3557737, 3557773, 3572357, 3572377, 3573223, 3573253, 3573337, 3573373, 3573523, 3573527, 3573727, 3573733, 3575333, 3575357, 3575573, 3577253, 3577333, 3577337, 3577573, 3577577, 3577727, 3722273, 3722357, 3723227, 3723233, 3723277, 3723337, 3723773, 3725233, 3725257, 3725357, 3725573, 3725753, 3727723, 3727727, 3727753, 3732373, 3732577, 3732727, 3733273, 3733333, 3733537, 3733757, 3735227, 3735233, 3735253, 3735323, 3735353, 3735377, 3735527, 3735553, 3735737, 3735773, 3737233, 3737323, 3737353, 3737557, 3752237, 3752327, 3752533, 3752773, 3753223, 3753257, 3753353, 3753377, 3753523, 3753553, 3755237, 3755273, 3755333, 3755753, 3757577, 3757723, 3757777, 3772337, 3772537, 3772577, 3772733, 3772753, 3772757, 3773257, 3773327, 3773377, 3773527, 3773573, 3773773, 3775333, 3775553, 3775573, 3775757, 3775777, 3777223, 3777233, 3777253, 3777377, 5222237, 5222323, 5222333, 5222533, 5222573, 5222753, 5223227, 5223377, 5223557, 5223577, 5223773, 5225237, 5225333, 5225377, 5225527, 5225533, 5225537, 5225723, 5225777, 5227253, 5227333, 5227723, 5227727, 5227753, 5227757, 5227777, 5232223, 5232257, 5232323, 5232553, 5232727, 5232737, 5233223, 5233237, 5233523, 5233577, 5233727, 5233777, 5235233, 5235253, 5235323, 5235353, 5235523, 5235553, 5235733, 5235757, 5237227, 5237237, 5237273, 5237327, 5237333, 5237527, 5237723, 5237753, 5252327, 5252333, 5252537, 5252773, 5253277, 5253757, 5255233, 5255357, 5255527, 5255573, 5255773, 5255777, 5257253, 5257277, 5257723, 5257727, 5272237, 5272327, 5272753, 5273227, 5273327, 5273537, 5273753, 5273777, 5275373, 5275537, 5275553, 5275573, 5275577, 5275723, 5275727, 5277227, 5277253, 5277257, 5277527, 5277773, 5322227, 5322253, 5322257, 5322277, 5322323, 5322353, 5322523, 5322533, 5322553, 5323273, 5323277, 5323757, 5323777, 5325223, 5325323, 5325337, 5325527, 5325533, 5325553, 5325737, 5327323, 5327327, 5327527, 5327537, 5327723, 5327737, 5332273, 5332333, 5332553, 5332753, 5333227, 5333233, 5333327, 5333353, 5333533, 5333557, 5335273, 5335723, 5335753, 5335777, 5337373, 5337377, 5337523, 5337533, 5337557, 5337733, 5337737, 5352257, 5352337, 5352533, 5353223, 5353357, 5353553, 5353727, 5353757, 5355257, 5355277, 5355577, 5355733, 5355737, 5357237, 5357353, 5357537, 5357557, 5357777, 5372233, 5372273, 5372333, 5372537, 5372723, 5372753, 5373233, 5373253, 5373527, 5373727, 5373733, 5373737, 5373773, 5375257, 5375273, 5375327, 5375533, 5375753, 5377237, 5377357, 5377373, 5377727, 5522233, 5522273, 5522327, 5522353, 5522527, 5523223, 5523227, 5523257, 5523373, 5523527, 5523773, 5525327, 5525753, 5525777, 5527237, 5527253, 5527573, 5527733, 5532223, 5532227, 5532377, 5532557, 5532577, 5532727, 5532757, 5533223, 5533273, 5533277, 5533337, 5533373, 5533523, 5533537, 5533553, 5533573, 5535223, 5535253, 5535337, 5535377, 5535773, 5537353, 5537377, 5537533, 5537737, 5552233, 5552737, 5552773, 5553227, 5553253, 5553277, 5553337, 5553727, 5553733, 5553773, 5555233, 5555237, 5555323, 5555357, 5555527, 5555723, 5555777, 5557333, 5557523, 5557537, 5557553, 5557723, 5557753, 5557757, 5572253, 5572733, 5573237, 5573257, 5573333, 5573353, 5573357, 5573377, 5573527, 5573573, 5573723, 5575237, 5575277, 5575357, 5575523, 5575553, 5575723, 5575777, 5577223, 5577277, 5577337, 5577527, 5577577, 5577727, 5722273, 5722333, 5722337, 5722373, 5722573, 5722733, 5722757, 5723233, 5723327, 5723737, 5725253, 5725273, 5725333, 5725523, 5725757, 5725777, 5727223, 5727277, 5727377, 5727523, 5732257, 5732273, 5732323, 5732527, 5732537, 5733223, 5733323, 5733337, 5733373, 5733523, 5733527, 5733737, 5733773, 5735357, 5735753, 5737357, 5737757, 5752223, 5752757, 5753273, 5753323, 5753353, 5753533, 5753557, 5753723, 5753777, 5755237, 5755357, 5755577, 5755733, 5755753, 5757223, 5757253, 5757277, 5757523, 5757553, 5757727, 5757733, 5757737, 5772227, 5772233, 5772337, 5772353, 5772527, 5772553, 5772773, 5773373, 5773553, 5773577, 5775337, 5775527, 5775557, 5777227, 5777237, 5777323, 5777353, 5777533, 5777537, 5777557, 5777573, 7222357, 7222373, 7222573, 7222723, 7222757, 7223323, 7223533, 7223537, 7223737, 7223773, 7225277, 7225327, 7225373, 7225723, 7227377, 7227527, 7232227, 7232233, 7232377, 7232527, 7232573, 7232737, 7233257, 7233277, 7233337, 7233377, 7233727, 7233773, 7235237, 7235273, 7235323, 7235533, 7235537, 7235573, 7235737, 7237253, 7237277, 7237333, 7237523, 7237553, 7237723, 7237753, 7237757, 7237777, 7252237, 7252253, 7252327, 7252373, 7252733, 7253333, 7253537, 7253723, 7253773, 7253777, 7255253, 7255357, 7255723, 7255727, 7255733, 7255757, 7257227, 7257253, 7257323, 7257527, 7257553, 7257577, 7257773, 7272227, 7272257, 7272337, 7272373, 7272527, 7272557, 7272737, 7273237, 7273337, 7273723, 7275227, 7275353, 7275377, 7275533, 7275733, 7275757, 7275773, 7277327, 7277533, 7277537, 7277573, 7277723, 7277737, 7322233, 7322537, 7322753, 7323353, 7323377, 7323523, 7323527, 7323557, 7323577, 7323733, 7323737, 7323773, 7325273, 7325333, 7325533, 7325557, 7325723, 7327237, 7327337, 7332257, 7332373, 7332733, 7333253, 7333327, 7333357, 7335257, 7335277, 7335353, 7335533, 7335553, 7335733, 7337227, 7337327, 7337333, 7337357, 7337723, 7337777, 7352273, 7352333, 7352353, 7352537, 7352777, 7353223, 7353233, 7353253, 7353373, 7353377, 7353527, 7353553, 7355233, 7355273, 7355323, 7355533, 7355573, 7355723, 7357223, 7357373, 7357577, 7372357, 7372523, 7372553, 7372753, 7373227, 7373237, 7373357, 7373537, 7373573, 7375223, 7375253, 7375273, 7375573, 7377233, 7377277, 7377373, 7377533, 7377577, 7522327, 7522573, 7523357, 7523533, 7523573, 7523777, 7525333, 7525723, 7525757, 7527253, 7527257, 7527523, 7527577, 7527727, 7532323, 7532527, 7532533, 7532537, 7532573, 7532773, 7533223, 7533377, 7533553, 7533577, 7533727, 7533733, 7535323, 7535527, 7537223, 7537237, 7537253, 7537333, 7537337, 7537373, 7537723, 7552277, 7552327, 7552537, 7552577, 7552723, 7552757, 7553327, 7553333, 7553573, 7553737, 7555333, 7555337, 7557227, 7557373, 7557523, 7557773, 7572223, 7572233, 7572337, 7572373, 7573253, 7573327, 7573537, 7573733, 7575223, 7575233, 7575277, 7575527, 7575577, 7577527, 7577723, 7577753, 7577777, 7722257, 7722277, 7722373, 7722527, 7722557, 7722773, 7723337, 7723357, 7723537, 7723553, 7723733, 7723753, 7723777, 7725323, 7725373, 7725527, 7725733, 7727233, 7727273, 7727323, 7727353, 7727777, 7732327, 7732337, 7732523, 7732553, 7732727, 7733233, 7733357, 7733377, 7733573, 7733723, 7735253, 7735327, 7735333, 7735537, 7735573, 7735577, 7735733, 7737337, 7737557, 7737733, 7752223, 7752253, 7752373, 7752377, 7752557, 7753337, 7753357, 7753523, 7755233, 7755277, 7755323, 7755337, 7755353, 7755773, 7757237, 7757257, 7757353, 7757537, 7757723, 7772333, 7772353, 7772753, 7772773, 7772777, 7773253, 7773257, 7773323, 7773523, 7775323, 7775377, 7775533, 7775737, 7775753, 7777223, 7777337, 7777537, 7777573, 7777727, 7777753]
def get_total_primes(a, b):
print(a, b)
check = True
for idx, p in enumerate(primes):
if p >= a and check:
low = idx
check = False
if p >= b:
hi = idx - 1
break
return hi + 1 - low
景越Python基础训练营QQ群 ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190919153035264.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2F1bXRvcHNhbGU=,size_16,color_FFFFFF,t_70) 欢迎各位同学加群讨论,一起学习,共同成长!