Skip to content

Commit e50b1d1

Browse files
author
GUO Joanna
committed
Add files via upload
1 parent 8426950 commit e50b1d1

File tree

8 files changed

+298
-27
lines changed

8 files changed

+298
-27
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Downloads](https://static.pepy.tech/personalized-badge/find-primes?period=total&units=international_system&left_color=lightgrey&right_color=yellowgreen&left_text=Downloads)](https://pepy.tech/project/find-primes)
1+
[![Downloads](https://static.pepy.tech/personalized-badge/find-primes?period=total&units=none&left_color=grey&right_color=yellowgreen&left_text=Downloads)](https://pepy.tech/project/find-primes)
22

33
Find Primes is a library to find all kinds of primes and factors of big numbers.
44

@@ -264,6 +264,36 @@ from find_primes import find_leylands_second_kind
264264
print(find_leylands_second_kind(58050))
265265
```
266266

267+
**[Woodall Primes](https://en.wikipedia.org/wiki/Woodall_number#Woodall_primes)**
268+
269+
A woodall prime is a woodall number that is a prime.
270+
271+
Example: Find all woodall primes below 400.
272+
```python
273+
from find_primes import find_woodalls
274+
print(find_woodalls(400))
275+
```
276+
277+
**[Unique Primes](https://en.wikipedia.org/wiki/Unique_prime_number)**
278+
279+
A unique prime is a prime that there is no other prime q such that the period length of the decimal expansion of its reciprocal, 1 / p, is equal to the period length of the reciprocal of q, 1 / q.
280+
281+
Example: Find all unique primes below 105.
282+
```python
283+
from find_primes import find_uniques
284+
print(find_uniques(105))
285+
```
286+
287+
**[Friedman Primes](https://en.wikipedia.org/wiki/Friedman_number)**
288+
289+
A friedman prime is a friedman number that is a prime.
290+
291+
Example: Find all friedman primes below 128.
292+
```python
293+
from find_primes import find_friedmans
294+
print(find_friedmans(128))
295+
```
296+
267297
**[MPQS Method](https://www.rieselprime.de/ziki/Multiple_polynomial_quadratic_sieve)**
268298

269299
The Multiple Polynomial Quadratic Sieve (MPQS) method is a factorization method.

build/lib/find_primes/__init__.py

Lines changed: 115 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,38 @@
1111
from sys import version, version_info
1212
from argparse import ArgumentParser
1313

14+
DEBUG = False
15+
VERBOSE = False
16+
1417
NUMPY_ENABLED = True
1518
try:
1619
from numpy import ones, nonzero, __version__
17-
print('Detected numpy version {__version__}'.format(**locals()))
20+
if VERBOSE: print('Detected numpy version {__version__}'.format(**locals()))
1821

1922
except ImportError:
2023
print('Numpy is not found! Finding primes will be slower!')
2124
NUMPY_ENABLED = False
2225

23-
PRIME_TEST = True
24-
FACTOR_TEST = True
26+
MPMATH_ENABLED = True
27+
try:
28+
from mpmath import cyclotomic, __version__
29+
if VERBOSE: print('Detected mpmath version {__version__}'.format(**locals()))
30+
31+
except ImportError:
32+
print('Mpmath is not found! You can\'t find several kinds of primes!')
33+
MPMATH_ENABLED = False
34+
35+
PRIME_TEST = FACTOR_TEST = not DEBUG
36+
2537
try:
2638
from rsa import newkeys, __version__
27-
print('Detected rsa version {__version__}'.format(**locals()))
39+
if VERBOSE: print('Detected rsa version {__version__}'.format(**locals()))
2840

2941
except ImportError:
3042
print('Rsa is not found! Factor Test will be disabled!')
3143
FACTOR_TEST = False
3244

33-
print()
45+
if VERBOSE: print()
3446

3547
LEFT = 'left'
3648
RIGHT = 'right'
@@ -88,9 +100,6 @@ def is_prime(n):
88100
def all_primes(n, output = 'array'):
89101
'''
90102
Return a prime list below n.
91-
92-
Arguments:
93-
output ----- 'array' or 'list' ----- The output type of the function.
94103
'''
95104
_check_num(n)
96105
if NUMPY_ENABLED:
@@ -114,6 +123,56 @@ def all_primes(n, output = 'array'):
114123
else:
115124
return [x for x in range(2, n + 1) if sieve[x]]
116125

126+
def get_repetend_length(denominator):
127+
'''
128+
Return the length of the repetend of n / denominator.
129+
'''
130+
length = 1
131+
if is_prime(denominator):
132+
while True:
133+
if (10 ** length - 1) % denominator == 0:
134+
break
135+
136+
length += 1
137+
138+
else:
139+
pass
140+
141+
return length
142+
'''
143+
output = ''
144+
all_num = []
145+
upload = []
146+
con = 10 // denominator
147+
r = 10 % denominator
148+
upload.append(con)
149+
upload.append(r)
150+
all_num.append(upload)
151+
while True:
152+
con = r * 10 // denominator
153+
r = r * 10 % denominator
154+
upload = []
155+
upload.append(con)
156+
upload.append(r)
157+
index1 = 0
158+
index2 = 0
159+
for x in all_num:
160+
if x == upload:
161+
for a in all_num:
162+
if index1 == index2:
163+
output += '['
164+
165+
output += str(a[0])
166+
index2 += 1
167+
168+
output += ']'
169+
return output.find(']') - output.find('[') - 1
170+
171+
index1 += 1
172+
173+
all_num.append(upload)
174+
'''
175+
117176
class FactorError(Exception):
118177
pass
119178

@@ -515,7 +574,6 @@ def find_leylands(n):
515574
for y in range(2, round(n ** 0.5)):
516575
if not y in all_x:
517576
ans = x ** y + y ** x
518-
#ans = fast_pow(x, y) + fast_pow(y, x)
519577
if ans < n and ans in primes:
520578
leylands.append(ans)
521579

@@ -534,7 +592,6 @@ def find_leylands_second_kind(n):
534592
for y in range(2, round(n ** 0.5)):
535593
if not y in all_x:
536594
ans = x ** y - y ** x
537-
#ans = fast_pow(x, y) - fast_pow(y, x)
538595
if ans < n and ans in primes:
539596
leylands_second_kind.append(ans)
540597

@@ -554,6 +611,52 @@ def find_woodalls(n):
554611

555612
return woodalls
556613

614+
def find_uniques(n):
615+
'''
616+
Return a list that has all unique primes below n.
617+
'''
618+
_check_num(n)
619+
primes = all_primes(n, output = 'list')
620+
try:
621+
primes.pop(primes.index(2))
622+
primes.pop(primes.index(5))
623+
624+
except ValueError:
625+
pass
626+
627+
uniques = []
628+
for x in primes:
629+
length = get_repetend_length(x)
630+
cyc = int(cyclotomic(length, 10))
631+
ans = cyc // gcd(cyc, length)
632+
c = log(ans, x)
633+
if int(c) == c:
634+
uniques.append(x)
635+
636+
return uniques
637+
from itertools import product, chain, permutations
638+
def find_friedmans(n):
639+
'''
640+
Return a list that has all friedman primes below n.
641+
'''
642+
_check_num(n)
643+
primes = all_primes(n)
644+
friedmans = []
645+
r = {}
646+
q = lambda n, h = 1: ['(' + i + c + j + ')' for (i, j), c in product(chain(*[product(*map(q, f)) for f in sum(([(x[:q], x[q:]) for q in range(1, len(x))] for x in map(''.join, permutations(n))), [])]), list('+-*/^') + [''] * h)] if 1 < len(n) else [n] * h
647+
for i, j in chain(*[product(q(str(s), 0), [s]) for s in range(125, n + 1)]):
648+
try:
649+
exec('if eval(%r) == j: r[j]=i' % i.replace('^', '**'))
650+
651+
except Exception:
652+
pass
653+
654+
for x, i in r.items():
655+
if x in primes:
656+
friedmans.append(x)
657+
658+
return friedmans
659+
557660
def factor_siqs(n):
558661
'''
559662
Return a list that has all factors of n.
@@ -3137,6 +3240,8 @@ def test():
31373240
print(f'Leyland Primes: {find_leylands(33000)}\n')
31383241
print(f'Leyland Primes of the second kind: {find_leylands_second_kind(58050)}\n')
31393242
print(f'Woodall Primes: {find_woodalls(400)}\n')
3243+
print(f'Unique Primes: {find_uniques(105)}\n')
3244+
print(f'Friedman Primes: {find_friedmans(128)}\n')
31403245
end_tm = time()
31413246
s = '\n' if FACTOR_TEST else ''
31423247
print(f'Prime Test Time: {round(end_tm - start_tm, 12)} seconds.' + s)
54.1 KB
Binary file not shown.

dist/find_primes-2.1.7.tar.gz

40.8 KB
Binary file not shown.

find_primes.egg-info/PKG-INFO

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Metadata-Version: 2.1
22
Name: find-primes
3-
Version: 2.1.6
4-
Summary: A module for finding primes and finding factors of big numbers.
3+
Version: 2.1.7
4+
Summary: A module to find primes and factors of big numbers.
55
Home-page: https://github.com/git4robot/pypi_find_primes
66
Author: JamesJ
77
Author-email: GGJamesQQ@yeah.net
@@ -15,7 +15,7 @@ Requires-Python: >=3.6.0
1515
Description-Content-Type: text/markdown
1616
License-File: LICENSE
1717

18-
[![Downloads](https://static.pepy.tech/personalized-badge/find-primes?period=total&units=international_system&left_color=lightgrey&right_color=yellowgreen&left_text=Downloads)](https://pepy.tech/project/find-primes)
18+
[![Downloads](https://static.pepy.tech/personalized-badge/find-primes?period=total&units=none&left_color=grey&right_color=yellowgreen&left_text=Downloads)](https://pepy.tech/project/find-primes)
1919

2020
Find Primes is a library to find all kinds of primes and factors of big numbers.
2121

@@ -281,6 +281,36 @@ from find_primes import find_leylands_second_kind
281281
print(find_leylands_second_kind(58050))
282282
```
283283

284+
**[Woodall Primes](https://en.wikipedia.org/wiki/Woodall_number#Woodall_primes)**
285+
286+
A woodall prime is a woodall number that is a prime.
287+
288+
Example: Find all woodall primes below 400.
289+
```python
290+
from find_primes import find_woodalls
291+
print(find_woodalls(400))
292+
```
293+
294+
**[Unique Primes](https://en.wikipedia.org/wiki/Unique_prime_number)**
295+
296+
A unique prime is a prime that there is no other prime q such that the period length of the decimal expansion of its reciprocal, 1 / p, is equal to the period length of the reciprocal of q, 1 / q.
297+
298+
Example: Find all unique primes below 105.
299+
```python
300+
from find_primes import find_uniques
301+
print(find_uniques(105))
302+
```
303+
304+
**[Friedman Primes](https://en.wikipedia.org/wiki/Friedman_number)**
305+
306+
A friedman prime is a friedman number that is a prime.
307+
308+
Example: Find all friedman primes below 128.
309+
```python
310+
from find_primes import find_friedmans
311+
print(find_friedmans(128))
312+
```
313+
284314
**[MPQS Method](https://www.rieselprime.de/ziki/Multiple_polynomial_quadratic_sieve)**
285315

286316
The Multiple Polynomial Quadratic Sieve (MPQS) method is a factorization method.

find_primes.egg-info/requires.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
numpy
22
rsa
3+
mpmath

0 commit comments

Comments
 (0)