我知道我的代码的复杂性不是最好的,我想它可能需要3-6分钟的运行,但我给了它15分钟,它没有停止。
我怎么知道它是卡在什么地方了还是还在跑?
我该怎么改进呢?import random
import time
def is_prime(m):
""" probabilistic test for compositeness of m>30
adds a trivial sieve to quickly eliminate divisibility
by small primes. """
if m in [2,3,5,7,11,13,17,19,23,29]:
return True # treats small primes separately
for prime in [2,3,5,7,11,13,17,19,23,29]:
if m % prime == 0:
return False
for i in range(0,100):
a = random.randint(1,m-1) # a is a random integer in [1..m-1]
if pow(a,m-1,m) != 1:
return False
return True
def order_safe_prime(g,p):
""" computes the order of g modulo a safe prime, p """
if g<1 or g>p-1:
return str.format("g={} is