示例#1
0
def test_search():
    assert 2 in sieve
    assert 2.1 not in sieve
    assert 1 not in sieve
    assert 2**1000 not in sieve
    raises(ValueError, lambda: sieve.search(1))
示例#2
0
def next_prime(value):
    """Returns the nearest prime at or after value, calculated using the sieve of Erastosthenes."""
    return sieve[sieve.search(value)[1]]
from modular_multiplicative_inverse import inverse
from sympy import sieve

I = inverse()
I.inv(3, 4)

N = 2028455971
s = 702505371
t = 188270011

print I.gcd(s, N)
print I.gcd(t, N)
a = I.gcd(s + t, N)
b = I.gcd(s - t, N)
N / I.gcd(s - t, N)
44027 * 46073

sieve.search(a)
sieve.search(b)
示例#4
0
def test_search():
    assert 2 in sieve
    assert 2.1 not in sieve
    assert 1 not in sieve
    assert 2**1000 not in sieve
    raises(ValueError, lambda: sieve.search(1))
示例#5
0
print(sieve[10])  # returns n th prime

sieve.extend_to_no(15)  # extends upto n th prime

# mobiusrange(a,b) genarates Mobius numbers for the range [a,b), means output will be a list.
Mob_func = sieve.mobiusrange(7, 12)
print('\n Mobius function outputs in the given range:', [i for i in Mob_func])

# primerange(a,b) generates all prime numbers in the range [a,b)
Prime_list = sieve.primerange(1, 5)
print('\n Primes in the given range are :', [i for i in Prime_list])

#search(n) return the indices i, j of the primes that bound n. If n is prime then i == j. Although n can be an expression,
# if ceiling cannot convert it to an integer then an error will be raised.
x, y = sieve.search(25)
print('\n The given input is in between ', '(', x, ',', y, ')', 'th Primes \n')

#totientrange(a, b) generates all totient numbers for the range [a, b). Simply it is a list of outputs
Totient_range = sieve.totientrange(1, 10)
print(' Values of Totient(n):', [i for i in Totient_range])

#sympy.ntheory.generate.prime(nth)  return the n th prime number. Logarithmic integral of x is a pretty nice approximation
# for number of primes <= x, i.e. li(x) ~ pi(x)
print('\n', 'See this! The 1000000th prime: ', generate.prime(1000000))

#sympy.ntheory.generate.primepi(n) returns the value of the prime counting function pi(n) = the number of prime numbers
# less than or equal to n.
print('\n', 'There are ', generate.primepi(40),
      ' primes < or = the given input')