Esempio n. 1
0
def count_primes(f, k):
    count = 0
    n = 0
    while 1:
        if is_prime(f(n), k):
            count += 1
        else: return count
        n += 1
Esempio n. 2
0
 def gen_prime(x):
     x = (int(x, base=16)**2) // 4 * 2 + 1
     while x < 4149515568880992958512407863691161151012446232242436899995657329690652811412908146399707048947103794288197886611300789182395151075411775307886874834113963687061181803401509523685376:
         x = (int(hashlib.sha512(
             str(x).encode(encoding='UTF-8')).hexdigest(),
                  base=16)**2) // 4 * 2 + 1
     while not prime.is_prime(x):
         x += 2
     return x
Esempio n. 3
0
 def test_is_prime(self):
     self.assertTrue(is_prime(7, 2))
     self.assertTrue(is_prime(13, 11))
     self.assertFalse(is_prime(6, 2))
Esempio n. 4
0
    # Find the length of the shortest cycle starting from x_mu
    # The hare moves while the tortoise stays still
    lam = 1
    h_x = t_x + 1
    while f(t_x)!= f(h_x):
        h_x = h_x + 1
        lam += 1
 
    return lam, mu

def brute_force():
    m = 0
    d = 0
    for i in xrange(2, 100):
        f = FMaker(i)
        (l, _) = floyd(f, 1)
        if l > m:
            m = l
            d = i
    print d, m

if __name__ == '__main__':
    from rabin_miller import is_prime
    p = 7
    for i in xrange(999, 7, -2):
        if is_prime(i, 3):
            p = i
            break
    (l, _) = floyd(FMaker(p), 1)
    print p, l