本文整理汇总了Python中sympy.ntheory.nextprime函数的典型用法代码示例。如果您正苦于以下问题:Python nextprime函数的具体用法?Python nextprime怎么用?Python nextprime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了nextprime函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: main7
def main7():
seed(0)
p = nextprime(randrange(2**96))
q = nextprime(randrange(2**97))
n = p * q
print(p, q, n)
print(qsieve(n))
开发者ID:wangjiezhe,项目名称:ent_note,代码行数:7,代码来源:rsa.py
示例2: main4
def main4():
print(crack_when_pq_close(23360947609))
p = nextprime(2**128)
print(p)
q = nextprime(p)
print(q)
print(crack_when_pq_close(p * q))
开发者ID:wangjiezhe,项目名称:ent_note,代码行数:7,代码来源:rsa.py
示例3: dmp_zz_collins_resultant
def dmp_zz_collins_resultant(f, g, u, K):
"""
Collins's modular resultant algorithm in `Z[X]`.
Examples
========
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.euclidtools import dmp_zz_collins_resultant
>>> f = ZZ.map([[1], [1, 2]])
>>> g = ZZ.map([[2, 1], [3]])
>>> dmp_zz_collins_resultant(f, g, 1, ZZ)
[-2, -5, 1]
"""
n = dmp_degree(f, u)
m = dmp_degree(g, u)
if n < 0 or m < 0:
return dmp_zero(u-1)
A = dmp_max_norm(f, u, K)
B = dmp_max_norm(g, u, K)
a = dmp_ground_LC(f, u, K)
b = dmp_ground_LC(g, u, K)
v = u - 1
B = K(2)*K.factorial(n+m)*A**m*B**n
r, p, P = dmp_zero(v), K.one, K.one
while P <= B:
p = K(nextprime(p))
while not (a % p) or not (b % p):
p = K(nextprime(p))
F = dmp_ground_trunc(f, p, u, K)
G = dmp_ground_trunc(g, p, u, K)
try:
R = dmp_zz_modular_resultant(F, G, p, u, K)
except HomomorphismFailed:
continue
if K.is_one(P):
r = R
else:
r = dmp_apply_pairs(r, R, _collins_crt, (P, p, K), v, K)
P *= p
return r
开发者ID:dyao-vu,项目名称:meta-core,代码行数:57,代码来源:euclidtools.py
示例4: dmp_zz_collins_resultant
def dmp_zz_collins_resultant(f, g, u, K):
"""
Collins's modular resultant algorithm in `Z[X]`.
Examples
========
>>> from sympy.polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = x + y + 2
>>> g = 2*x*y + x + 3
>>> R.dmp_zz_collins_resultant(f, g)
-2*y**2 - 5*y + 1
"""
n = dmp_degree(f, u)
m = dmp_degree(g, u)
if n < 0 or m < 0:
return dmp_zero(u - 1)
A = dmp_max_norm(f, u, K)
B = dmp_max_norm(g, u, K)
a = dmp_ground_LC(f, u, K)
b = dmp_ground_LC(g, u, K)
v = u - 1
B = K(2)*K.factorial(K(n + m))*A**m*B**n
r, p, P = dmp_zero(v), K.one, K.one
while P <= B:
p = K(nextprime(p))
while not (a % p) or not (b % p):
p = K(nextprime(p))
F = dmp_ground_trunc(f, p, u, K)
G = dmp_ground_trunc(g, p, u, K)
try:
R = dmp_zz_modular_resultant(F, G, p, u, K)
except HomomorphismFailed:
continue
if K.is_one(P):
r = R
else:
r = dmp_apply_pairs(r, R, _collins_crt, (P, p, K), v, K)
P *= p
return r
开发者ID:AdrianPotter,项目名称:sympy,代码行数:57,代码来源:euclidtools.py
示例5: rsa
def rsa(bits):
p = nextprime(randrange(2**(bits // 2 + 1)))
q = nextprime(randrange(2**(bits // 2 + 1)))
n = p * q
phi_n = (p - 1) * (q - 1)
while True:
e = randrange(1, phi_n)
if gcd(e, phi_n) == 1:
break
d = inv_mod(e, phi_n)
return e, d, n
开发者ID:wangjiezhe,项目名称:ent_note,代码行数:11,代码来源:rsa.py
示例6: GetLongestConsSumPrimes
def GetLongestConsSumPrimes(step,limit):
sum = step
count = 1
i = nextprime(step)
while (sum + i)<limit:
sum += i
count += 1
i = nextprime(i)
while isprime(sum) == False :
i = prevprime(i)
sum -= i
count -= 1
return (count,sum)
开发者ID:azusa0127,项目名称:ProjectEuler,代码行数:15,代码来源:p50.py
示例7: swinnerton_dyer_poly
def swinnerton_dyer_poly(n, x=None, **args):
"""Generates n-th Swinnerton-Dyer polynomial in `x`. """
if n <= 0:
raise ValueError(
"can't generate Swinnerton-Dyer polynomial of order %s" % n)
if x is not None:
x, cls = sympify(x), Poly
else:
x, cls = Dummy('x'), PurePoly
p, elts = 2, [[x, -sqrt(2)],
[x, sqrt(2)]]
for i in xrange(2, n + 1):
p, _elts = nextprime(p), []
neg_sqrt = -sqrt(p)
pos_sqrt = +sqrt(p)
for elt in elts:
_elts.append(elt + [neg_sqrt])
_elts.append(elt + [pos_sqrt])
elts = _elts
poly = []
for elt in elts:
poly.append(Add(*elt))
if not args.get('polys', False):
return Mul(*poly).expand()
else:
return PurePoly(Mul(*poly), x)
开发者ID:Acebulf,项目名称:sympy,代码行数:35,代码来源:specialpolys.py
示例8: swinnerton_dyer_poly
def swinnerton_dyer_poly(n, x=None, **args):
"""Generates n-th Swinnerton-Dyer polynomial in `x`. """
from numberfields import minimal_polynomial
if n <= 0:
raise ValueError(
"can't generate Swinnerton-Dyer polynomial of order %s" % n)
if x is not None:
sympify(x)
else:
x = Dummy('x')
if n > 3:
p = 2
a = [sqrt(2)]
for i in xrange(2, n + 1):
p = nextprime(p)
a.append(sqrt(p))
return minimal_polynomial(Add(*a), x, polys=args.get('polys', False))
if n == 1:
ex = x**2 - 2
elif n == 2:
ex = x**4 - 10*x**2 + 1
elif n == 3:
ex = x**8 - 40*x**6 + 352*x**4 - 960*x**2 + 576
if not args.get('polys', False):
return ex
else:
return PurePoly(ex, x)
开发者ID:alhirzel,项目名称:sympy,代码行数:30,代码来源:specialpolys.py
示例9: swinnerton_dyer_poly
def swinnerton_dyer_poly(n, x=None, **args):
"""Generates n-th Swinnerton-Dyer polynomial in `x`. """
if n <= 0:
raise ValueError("can't generate Swinnerton-Dyer polynomial of order %s" % n)
if x is not None:
x = sympify(x)
else:
x = Symbol('x', dummy=True)
p, elts = 2, [[x, -2**Rational(1,2)],
[x, 2**Rational(1,2)]]
for i in xrange(2, n+1):
p, _elts = nextprime(p), []
neg_sqrt = -p**Rational(1,2)
pos_sqrt = +p**Rational(1,2)
for elt in elts:
_elts.append(elt + [neg_sqrt])
_elts.append(elt + [pos_sqrt])
elts = _elts
poly = []
for elt in elts:
poly.append(Add(*elt))
if not args.get('polys', False):
return Mul(*poly).expand()
else:
return Poly(Mul(*poly))
开发者ID:Sumith1896,项目名称:sympy-polys,代码行数:34,代码来源:specialpolys.py
示例10: test_generate
def test_generate():
assert nextprime(-4) == 2
assert nextprime(2) == 3
assert nextprime(5) == 7
assert nextprime(90) == 97
assert nextprime(10**40) == (10**40 + 121)
assert prevprime(3) == 2
assert prevprime(7) == 5
assert prevprime(97) == 89
assert prevprime(10**40) == (10**40 - 17)
assert list(primerange(2, 7)) == [2, 3, 5]
assert list(primerange(2, 10)) == [2, 3, 5, 7]
assert list(primerange(1050, 1100)) == [1051, 1061, \
1063, 1069, 1087, 1091, 1093, 1097]
s = Sieve()
for i in range(30, 2350, 376):
for j in range(2, 5096, 1139):
A = list(s.primerange(i, i+j))
B = list(primerange(i, i+j))
assert A == B
s = Sieve()
assert s[10] == 29
开发者ID:smichr,项目名称:sympy-live,代码行数:22,代码来源:test_ntheory.py
示例11: doProblem
def doProblem():
LIMIT = 1000000
step = 2
maxLength = 0
maxIndex = 0
maxSum = 0
while step < (LIMIT-maxSum):
if GetLongestConsSumPrimes(step,LIMIT)[0] > maxLength:
maxLength = GetLongestConsSumPrimes(step,LIMIT)[0]
maxSum = GetLongestConsSumPrimes(step,LIMIT)[1]
maxIndex = step
print(maxIndex,maxLength,maxSum)
step = nextprime(step)
return (maxIndex,maxLength,maxSum)
开发者ID:azusa0127,项目名称:ProjectEuler,代码行数:14,代码来源:p50.py
示例12: _inv_totient_estimate
def _inv_totient_estimate(m):
"""
Find ``(L, U)`` such that ``L <= phi^-1(m) <= U``.
Examples
========
>>> from sympy.polys.polyroots import _inv_totient_estimate
>>> _inv_totient_estimate(192)
(192, 840)
>>> _inv_totient_estimate(400)
(400, 1750)
"""
primes = [ d + 1 for d in divisors(m) if isprime(d + 1) ]
a, b = 1, 1
for p in primes:
a *= p
b *= p - 1
L = m
U = int(math.ceil(m*(float(a)/b)))
P = p = 2
primes = []
while P <= U:
p = nextprime(p)
primes.append(p)
P *= p
P //= p
b = 1
for p in primes[:-1]:
b *= p - 1
U = int(math.ceil(m*(float(P)/b)))
return L, U
开发者ID:bjodah,项目名称:sympy,代码行数:43,代码来源:polyroots.py
示例13: test_generate
def test_generate():
assert nextprime(-4) == 2
assert nextprime(2) == 3
assert nextprime(5) == 7
assert nextprime(12) == 13
assert nextprime(90) == 97
assert nextprime(10**40) == (10**40 + 121)
assert prevprime(3) == 2
assert prevprime(7) == 5
assert prevprime(13) == 11
assert prevprime(97) == 89
assert prevprime(10**40) == (10**40 - 17)
assert list(primerange(2, 7)) == [2, 3, 5]
assert list(primerange(2, 10)) == [2, 3, 5, 7]
assert list(primerange(1050, 1100)) == [1051, 1061,
1063, 1069, 1087, 1091, 1093, 1097]
s = Sieve()
for i in range(30, 2350, 376):
for j in range(2, 5096, 1139):
A = list(s.primerange(i, i + j))
B = list(primerange(i, i + j))
assert A == B
s = Sieve()
assert s[10] == 29
assert nextprime(2, 2) == 5
raises(ValueError, lambda: totient(0))
raises(ValueError, lambda: reduced_totient(0))
raises(ValueError, lambda: primorial(0))
assert mr(1, [2]) is False
func = lambda i: (i**2 + 1) % 51
assert next(cycle_length(func, 4)) == (6, 2)
assert list(cycle_length(func, 4, values=True)) == \
[17, 35, 2, 5, 26, 14, 44, 50, 2, 5, 26, 14]
assert next(cycle_length(func, 4, nmax=5)) == (5, None)
assert list(cycle_length(func, 4, nmax=5, values=True)) == \
[17, 35, 2, 5, 26]
开发者ID:JamesdeLisle,项目名称:sympy,代码行数:42,代码来源:test_generate.py
示例14: swinnerton_dyer_poly
def swinnerton_dyer_poly(n, x=None, polys=False):
"""Generates n-th Swinnerton-Dyer polynomial in `x`.
Parameters
----------
n : int
`n` decides the order of polynomial
x : optional
polys : bool, optional
``polys=True`` returns an expression, otherwise
(default) returns an expression.
"""
from .numberfields import minimal_polynomial
if n <= 0:
raise ValueError(
"can't generate Swinnerton-Dyer polynomial of order %s" % n)
if x is not None:
sympify(x)
else:
x = Dummy('x')
if n > 3:
p = 2
a = [sqrt(2)]
for i in range(2, n + 1):
p = nextprime(p)
a.append(sqrt(p))
return minimal_polynomial(Add(*a), x, polys=args.get('polys', False))
if n == 1:
ex = x**2 - 2
elif n == 2:
ex = x**4 - 10*x**2 + 1
elif n == 3:
ex = x**8 - 40*x**6 + 352*x**4 - 960*x**2 + 576
return PurePoly(ex, x) if polys else ex
开发者ID:carstimon,项目名称:sympy,代码行数:38,代码来源:specialpolys.py
示例15: dmp_zz_wang
def dmp_zz_wang(f, u, K, **args):
"""Factor primitive square-free polynomials in `Z[X]`.
Given a multivariate polynomial `f` in `Z[x_1,...,x_n]`, which
is primitive and square-free in `x_1`, computes factorization
of `f` into irreducibles over integers.
The procedure is based on Wang's Enhanced Extended Zassenhaus
algorithm. The algorithm works by viewing `f` as a univariate
polynomial in `Z[x_2,...,x_n][x_1]`, for which an evaluation
mapping is computed::
x_2 -> a_2, ..., x_n -> a_n
where `a_i`, for `i = 2, ..., n`, are carefully chosen integers.
The mapping is used to transform `f` into a univariate polynomial
in `Z[x_1]`, which can be factored efficiently using Zassenhaus
algorithm. The last step is to lift univariate factors to obtain
true multivariate factors. For this purpose a parallel Hensel
lifting procedure is used.
References
==========
.. [Wang78] P. S. Wang, An Improved Multivariate Polynomial Factoring
Algorithm, Math. of Computation 32, 1978, pp. 1215--1231
.. [Geddes92] K. Geddes, S. R. Czapor, G. Labahn, Algorithms for
Computer Algebra, Springer, 1992, pp. 264--272
"""
ct, T = dmp_zz_factor(dmp_LC(f, K), u-1, K)
b = dmp_zz_mignotte_bound(f, u, K)
p = K(nextprime(b))
eez_mod = args.get('mod', None)
if eez_mod is None:
if u == 1:
eez_mod = 2
else:
eez_mod = 1
history, configs, A, r = set([]), [], [K.zero]*u, None
try:
cs, s, E = dmp_zz_wang_test_points(f, T, ct, A, u, K)
_, H = dup_zz_factor_sqf(s, K)
r = len(H)
if r == 1:
return [f]
bad_points = set([tuple(A)])
configs = [(s, cs, E, H, A)]
except EvaluationFailed:
pass
while len(configs) < EEZ_NUM_OK:
for _ in xrange(EEZ_NUM_TRY):
A = [ K(randint(-eez_mod, eez_mod)) for _ in xrange(u) ]
if tuple(A) not in history:
history.add(tuple(A))
else:
continue
try:
cs, s, E = dmp_zz_wang_test_points(f, T, ct, A, u, K)
except EvaluationFailed:
continue
_, H = dup_zz_factor_sqf(s, K)
rr = len(H)
if r is not None:
if rr != r: # pragma: no cover
if rr < r:
configs, r = [], rr
else:
continue
else:
r = rr
if r == 1:
return [f]
configs.append((s, cs, E, H, A))
if len(configs) == EEZ_NUM_OK:
break
else:
eez_mod += EEZ_MOD_STEP
s_norm, s_arg, i = None, 0, 0
for s, _, _, _, _ in configs:
#.........这里部分代码省略.........
开发者ID:Aang,项目名称:sympy,代码行数:101,代码来源:factortools.py
示例16: test_factorint
def test_factorint():
assert primefactors(123456) == [2, 3, 643]
assert factorint(0) == {0: 1}
assert factorint(1) == {}
assert factorint(-1) == {-1: 1}
assert factorint(-2) == {-1: 1, 2: 1}
assert factorint(-16) == {-1: 1, 2: 4}
assert factorint(2) == {2: 1}
assert factorint(126) == {2: 1, 3: 2, 7: 1}
assert factorint(123456) == {2: 6, 3: 1, 643: 1}
assert factorint(5951757) == {3: 1, 7: 1, 29: 2, 337: 1}
assert factorint(64015937) == {7993: 1, 8009: 1}
assert factorint(2**(2**6) + 1) == {274177: 1, 67280421310721: 1}
assert multiproduct(factorint(fac(200))) == fac(200)
for b, e in factorint(fac(150)).items():
assert e == fac_multiplicity(150, b)
assert factorint(103005006059**7) == {103005006059: 7}
assert factorint(31337**191) == {31337: 191}
assert factorint(2**1000 * 3**500 * 257**127 * 383**60) == \
{2: 1000, 3: 500, 257: 127, 383: 60}
assert len(factorint(fac(10000))) == 1229
assert factorint(12932983746293756928584532764589230) == \
{2: 1, 5: 1, 73: 1, 727719592270351: 1, 63564265087747: 1, 383: 1}
assert factorint(727719592270351) == {727719592270351: 1}
assert factorint(2**64 + 1, use_trial=False) == factorint(2**64 + 1)
for n in range(60000):
assert multiproduct(factorint(n)) == n
assert pollard_rho(2**64 + 1, seed=1) == 274177
assert pollard_rho(19, seed=1) is None
assert factorint(3, limit=2) == {3: 1}
assert factorint(12345) == {3: 1, 5: 1, 823: 1}
assert factorint(
12345, limit=3) == {4115: 1, 3: 1} # the 5 is greater than the limit
assert factorint(1, limit=1) == {}
assert factorint(0, 3) == {0: 1}
assert factorint(12, limit=1) == {12: 1}
assert factorint(30, limit=2) == {2: 1, 15: 1}
assert factorint(16, limit=2) == {2: 4}
assert factorint(124, limit=3) == {2: 2, 31: 1}
assert factorint(4*31**2, limit=3) == {2: 2, 31: 2}
p1 = nextprime(2**32)
p2 = nextprime(2**16)
p3 = nextprime(p2)
assert factorint(p1*p2*p3) == {p1: 1, p2: 1, p3: 1}
assert factorint(13*17*19, limit=15) == {13: 1, 17*19: 1}
assert factorint(1951*15013*15053, limit=2000) == {225990689: 1, 1951: 1}
assert factorint(primorial(17) + 1, use_pm1=0) == \
{long(19026377261): 1, 3467: 1, 277: 1, 105229: 1}
# when prime b is closer than approx sqrt(8*p) to prime p then they are
# "close" and have a trivial factorization
a = nextprime(2**2**8) # 78 digits
b = nextprime(a + 2**2**4)
assert 'Fermat' in capture(lambda: factorint(a*b, verbose=1))
raises(ValueError, lambda: pollard_rho(4))
raises(ValueError, lambda: pollard_pm1(3))
raises(ValueError, lambda: pollard_pm1(10, B=2))
# verbose coverage
n = nextprime(2**16)*nextprime(2**17)*nextprime(1901)
assert 'with primes' in capture(lambda: factorint(n, verbose=1))
capture(lambda: factorint(nextprime(2**16)*1012, verbose=1))
n = nextprime(2**17)
capture(lambda: factorint(n**3, verbose=1)) # perfect power termination
capture(lambda: factorint(2*n, verbose=1)) # factoring complete msg
# exceed 1st
n = nextprime(2**17)
n *= nextprime(n)
assert '1000' in capture(lambda: factorint(n, limit=1000, verbose=1))
n *= nextprime(n)
assert len(factorint(n)) == 3
assert len(factorint(n, limit=p1)) == 3
n *= nextprime(2*n)
# exceed 2nd
assert '2001' in capture(lambda: factorint(n, limit=2000, verbose=1))
assert capture(
lambda: factorint(n, limit=4000, verbose=1)).count('Pollard') == 2
# non-prime pm1 result
n = nextprime(8069)
n *= nextprime(2*n)*nextprime(2*n, 2)
capture(lambda: factorint(n, verbose=1)) # non-prime pm1 result
# factor fermat composite
p1 = nextprime(2**17)
p2 = nextprime(2*p1)
assert factorint((p1*p2**2)**3) == {p1: 3, p2: 6}
# Test for non integer input
raises(ValueError, lambda: factorint(4.5))
开发者ID:LuckyStrikes1090,项目名称:sympy,代码行数:88,代码来源:test_ntheory.py
示例17: dmp_zz_wang
def dmp_zz_wang(f, u, K, mod=None):
"""
Factor primitive square-free polynomials in `Z[X]`.
Given a multivariate polynomial `f` in `Z[x_1,...,x_n]`, which
is primitive and square-free in `x_1`, computes factorization
of `f` into irreducibles over integers.
The procedure is based on Wang's Enhanced Extended Zassenhaus
algorithm. The algorithm works by viewing `f` as a univariate
polynomial in `Z[x_2,...,x_n][x_1]`, for which an evaluation
mapping is computed::
x_2 -> a_2, ..., x_n -> a_n
where `a_i`, for `i = 2, ..., n`, are carefully chosen integers.
The mapping is used to transform `f` into a univariate polynomial
in `Z[x_1]`, which can be factored efficiently using Zassenhaus
algorithm. The last step is to lift univariate factors to obtain
true multivariate factors. For this purpose a parallel Hensel
lifting procedure is used.
**References**
1. [Wang78]_
2. [Geddes92]_
"""
ct, T = dmp_zz_factor(dmp_LC(f, K), u-1, K)
b = dmp_zz_mignotte_bound(f, u, K)
p = K(nextprime(b))
if mod is None:
if u == 1:
mod = 2
else:
mod = 1
history, configs, A, r = set([]), [], [K.zero]*u, None
try:
cs, s, E = dmp_zz_wang_test_points(f, T, ct, A, u, K)
_, H = dup_zz_factor_sqf(s, K)
r = len(H)
if r == 1:
return [f]
bad_points = set([tuple(A)])
configs = [(s, cs, E, H, A)]
except EvaluationFailed:
pass
eez_num_configs = query('EEZ_NUMBER_OF_CONFIGS')
eez_num_tries = query('EEZ_NUMBER_OF_TRIES')
eez_mod_step = query('EEZ_MODULUS_STEP')
while len(configs) < eez_num_configs:
for _ in xrange(eez_num_tries):
A = [ K(randint(-mod, mod)) for _ in xrange(u) ]
if tuple(A) not in history:
history.add(tuple(A))
else:
continue
try:
cs, s, E = dmp_zz_wang_test_points(f, T, ct, A, u, K)
except EvaluationFailed:
continue
_, H = dup_zz_factor_sqf(s, K)
rr = len(H)
if r is not None:
if rr != r: # pragma: no cover
if rr < r:
configs, r = [], rr
else:
continue
else:
r = rr
if r == 1:
return [f]
configs.append((s, cs, E, H, A))
if len(configs) == eez_num_configs:
break
else:
mod += eez_mod_step
s_norm, s_arg, i = None, 0, 0
for s, _, _, _, _ in configs:
#.........这里部分代码省略.........
开发者ID:TeddyBoomer,项目名称:wxgeometrie,代码行数:101,代码来源:factortools.py
示例18: sumcons
# than previous streak... (streak, sum)
# 3. subtract lowest prime in streak
# 4. repeat 1-3 until max series length < streak
def sumcons(Nmin, Nmax):
retval = (-1, -1)
tot = 0
for i, n in enumerate(nt.primerange(Nmin, Nmax)):
if i == 0:
continue
if tot >= Nmax:
break
if nt.isprime(tot):
retval = (i, tot)
tot = tot + n
return retval
Nmax = 1000000
start = 1
nconsprimes = []
tots = []
while start < Nmax:
(n, N) = sumcons(start, Nmax)
if n > 0:
nconsprimes.append(n)
tots.append(N)
start = nt.nextprime(start)
print(max([(n, N) for (n, N) in zip(nconsprimes, tots) if n > 20]))
开发者ID:evan-phelps,项目名称:project-euler,代码行数:30,代码来源:p50.py
示例19: test_generate
def test_generate():
from sympy.ntheory.generate import sieve
sieve._reset()
assert nextprime(-4) == 2
assert nextprime(2) == 3
assert nextprime(5) == 7
assert nextprime(12) == 13
assert prevprime(3) == 2
assert prevprime(7) == 5
assert prevprime(13) == 11
assert prevprime(19) == 17
assert prevprime(20) == 19
sieve.extend_to_no(9)
assert sieve._list[-1] == 23
assert sieve._list[-1] < 31
assert 31 in sieve
assert nextprime(90) == 97
assert nextprime(10**40) == (10**40 + 121)
assert prevprime(97) == 89
assert prevprime(10**40) == (10**40 - 17)
assert list(sieve.primerange(10, 1)) == []
assert list(sieve.primerange(5, 9)) == [5, 7]
sieve._reset(prime=True)
assert list(sieve.primerange(2, 12)) == [2, 3, 5, 7, 11]
assert list(sieve.totientrange(5, 15)) == [4, 2, 6, 4, 6, 4, 10, 4, 12, 6]
sieve._reset(totient=True)
assert list(sieve.totientrange(3, 13)) == [2, 2, 4, 2, 6, 4, 6, 4, 10, 4]
assert list(sieve.totientrange(900, 1000)) == [totient(x) for x in range(900, 1000)]
assert list(sieve.totientrange(0, 1)) == []
assert list(sieve.totientrange(1, 2)) == [1]
assert list(sieve.mobiusrange(5, 15)) == [-1, 1, -1, 0, 0, 1, -1, 0, -1, 1]
sieve._reset(mobius=True)
assert list(sieve.mobiusrange(3, 13)) == [-1, 0, -1, 1, -1, 0, 0, 1, -1, 0]
assert list(sieve.mobiusrange(1050, 1100)) == [mobius(x) for x in range(1050, 1100)]
assert list(sieve.mobiusrange(0, 1)) == []
assert list(sieve.mobiusrange(1, 2)) == [1]
assert list(primerange(10, 1)) == []
assert list(primerange(2, 7)) == [2, 3, 5]
assert list(primerange(2, 10)) == [2, 3, 5, 7]
assert list(primerange(1050, 1100)) == [1051, 1061,
1063, 1069, 1087, 1091, 1093, 1097]
s = Sieve()
for i in range(30, 2350, 376):
for j in range(2, 5096, 1139):
A = list(s.primerange(i, i + j))
B = list(primerange(i, i + j))
assert A == B
s = Sieve()
assert s[10] == 29
assert nextprime(2, 2) == 5
raises(ValueError, lambda: totient(0))
raises(ValueError, lambda: reduced_totient(0))
raises(ValueError, lambda: primorial(0))
assert mr(1, [2]) is False
func = lambda i: (i**2 + 1) % 51
assert next(cycle_length(func, 4)) == (6, 2)
assert list(cycle_length(func, 4, values=True)) == \
[17, 35, 2, 5, 26, 14, 44, 50, 2, 5, 26, 14]
assert next(cycle_length(func, 4, nmax=5)) == (5, None)
assert list(cycle_length(func, 4, nmax=5, values=True)) == \
[17, 35, 2, 5, 26]
sieve.extend(3000)
assert nextprime(2968) == 2969
assert prevprime(2930) == 2927
raises(ValueError, lambda: prevprime(1))
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:78,代码来源:test_generate.py
注:本文中的sympy.ntheory.nextprime函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论