mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Use sympy for faster factorization if available (#199)
This commit is contained in:
parent
7e85a3cda4
commit
9f812d83a9
|
@ -127,6 +127,11 @@ There you'll find a list of all the methods, types and available constructors.
|
|||
|
||||
More examples are also available under the ``telethon_examples/`` folder.
|
||||
|
||||
If you're using Telethon under ARM, you may want to install ``sympy`` through
|
||||
``pip`` for a substantial speed-up when generating the keys required to
|
||||
connect to Telegram (you can of course do this on desktop too). See
|
||||
`issue #199 <https://github.com/LonamiWebs/Telethon/issues/199>`_ for more.
|
||||
|
||||
Common errors
|
||||
-------------
|
||||
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
from random import randint
|
||||
try:
|
||||
import sympy.ntheory
|
||||
except ImportError:
|
||||
sympy = None
|
||||
|
||||
|
||||
class Factorization:
|
||||
|
@ -58,5 +62,8 @@ class Factorization:
|
|||
@staticmethod
|
||||
def factorize(pq):
|
||||
"""Factorizes the given number and returns both the divisor and the number divided by the divisor"""
|
||||
if sympy:
|
||||
return tuple(sympy.ntheory.factorint(pq).keys())
|
||||
else:
|
||||
divisor = Factorization.find_small_multiplier_lopatin(pq)
|
||||
return divisor, pq // divisor
|
||||
|
|
Loading…
Reference in New Issue
Block a user