Your IP : 3.135.212.244


Current Path : /opt/alt/python313/lib64/python3.13/__pycache__/
Upload File :
Current File : //opt/alt/python313/lib64/python3.13/__pycache__/_pylong.cpython-313.opt-1.pyc

�

*}g6.��d�SrSSKrSSKrSSKrSSjr\R"5R5r\R\l
\R\l\R\lS\R\R 'SrSrSrSrS	rS
rSrSrS
rSrSrSrg!\a SrN�f=f)a�Python implementations of some algorithms for use by longobject.c.
The goal is to provide asymptotically faster algorithms that can be
used for operations on integers with many digits.  In those cases, the
performance overhead of the Python implementation is not significant
since the asymptotic behavior is what dominates runtime. Functions
provided by this module should be considered private and not part of any
public API.

Note: for ease of maintainability, please prefer clear code and avoid
"micro-optimizations".  This module will only be imported and used for
integers with a huge number of digits.  Saving a few microseconds with
tricky or non-obvious code is not worth it.  For people looking for
maximum performance, they should use something like gmpy2.�Nc��[5n[5nU1nU(a{UR5nX;dX::aM#URU5 US-	nURU5 URU5 US-(aURUS-5 U(aM{0nU(dU$[[	U55n	[U	5n
U(a[
SU
5 X-X�'U	HqnUS-
U;a!U(a[
SU5 X�S-
U-X�'M-US-	nX�-
nU(a[
SU5 X�X�-n
X�:waU(a[
S5 X�-n
X�U'Ms U$)N�zpow atz	* base atz	square atz    and * base)�set�pop�add�iter�sorted�next�print)�w�base�	more_than�show�seen�need�ws�lo�d�it�first�this�hi�sqs              �./opt/alt/python313/lib64/python3.13/_pylong.py�compute_powersr3s:���5�D��5�D�
��B�
��F�F�H���9���������
�!�V�������
���r�
��q�5��F�F�2��6�N�
�"�	�A����	
�f�T�l�	�B���H�E��
�h����}�A�H����!�8�q�=���k�4�(��q��k�D�(�A�G����B���B���k�4�(������B��x���*�+��
���d�G�'�(
�H�rc� ^^^^�SSKJm SmUUUU4Sjm[R"[5 UR	5n[UT"S5T5mUS:aSnU*nOSnT"X5nU(aU*nSSS5 U$!,(df   W$=f)	z6Asymptotically fast conversion of an 'int' to Decimal.r)�Decimal��c�|>�UT::aT"U5$US-	nX-	nUSU-S-
-nT"XB5T"X1U-
5TU--$�Nr�)	�nr�w2rr�BITLIM�D�inner�w2pows	     ����rr'�int_to_decimal.<locals>.innerysV�����;��Q�4�K�
�!�V��
�W��
�1��7�a�-�
 ���R�}�u�R�R��0�5��9�<�<�<r�TFN)�decimalr�localcontext�_unbounded_dec_context�
bit_lengthr)r#�nbits�negate�resultr%r&r'r(s    @@@@r�int_to_decimalr2gs����%�
�F�=�=�
�	�	�4�	5�������u�a��d�F�3���q�5��F���A��F��q�����W�F�
6��M�
6�	5��M�s�AA>�>
B
c�p^^^�UR5nUS:�a[b[[U55$SmUUU4Sjm[	US-S-5n[UST5mTR
5Hup#X2-TU'M US:aU*nSnOS	nT"X5nUSS
:XaU(aURS
5nXE-$)z?Asymptotically fast conversion of an 'int' to a decimal string.i��i�c�>�UT::a[U5$US-	n[UTU5up4T"X1U-
5T"XB5RU5-$r!)�str�divmod�zfill)r#rr$rr�DIGLIMr'�pow10s     ���rr'�$int_to_decimal_string.<locals>.inner�sQ�����;��q�6�M�
�!�V����5��9�%����R�R�� �5��=�#6�#6�r�#:�:�:rg�y�PD�?r�r�-��0)r.�_decimalr5r2�intr�items�lstrip)	r#r�k�v�sign�sr8r'r9s	      @@@r�int_to_decimal_stringrG�s����	����A��7�{�x�+��>�!�$�%�%��F�;�	�A�"�"�Q�&�'�A��1�a��(�E����
����6��a����1�u�
�B������
�a��A���t�s�{�q�
�H�H�S�M���8�Orc�p^^^^�SmUUUU4Sjm[[T5ST5mT"S[T55$)z6Asymptotically fast conversion of a 'str' to an 'int'.ic�~>�X-
T::a
[TX5$X-S-S-	nT"X!5T"X5TX-
-X-
--$r!)r@)�a�b�midr8r'rF�w5pows   ����rr'� _str_to_int_inner.<locals>.inner�sW����5�F�?��q��v�;���u�q�y�Q����c�
��!�M�E�!�'�N�2���!�"�	#rr;r)r�len)rFr8r'rMs`@@@r�_str_to_int_innerrP�s9����F�#�#�
�3�q�6�1�f�-�E���C��F��rc�X�UR5RSS5n[U5$)zkAsymptotically fast version of PyLong_FromString(), conversion
of a string of decimal digits into an 'int'.�_r=)�rstrip�replacerP)rFs r�int_from_stringrU�s'��	
���
���3��#�A��Q��rc��[R"SU5nU(d[S5e[UR	S55nUR	S5S:XaU*nU$)zBAsymptotically fast version of decimal string to 'int' conversion.z\s*([+-]?)([0-9_]+)\s*z&invalid literal for int() with base 10r*rr<)�re�match�
ValueErrorrU�group)rF�mrDs   r�
str_to_intr\�sR��	���*�A�.�A���A�B�B������
�#�A��w�w�q�z�S��
�B���Hri�c�(�UR5U-
[::a[X5$US-nU(aUS-nUS-nUS-
nUS-	nSU-S-
nX-	X-pv[X-	X-	U-XXt5up�[X�U-XXt5up�U(aU	S-n	X�-U
-U	4$)a2Divide a 2n-bit nonnegative integer a by an n-bit positive integer
b, using a recursive divide-and-conquer algorithm.

Inputs:
  n is a positive integer
  b is a positive integer with exactly n bits
  a is a nonnegative integer such that a < 2**n * b

Output:
  (q, r) such that a = b*q+r and 0 <= r < b.

r)r.�
_DIV_LIMITr6�_div3n2n)rJrKr#�pad�half_n�mask�b1�b2�q1�r�q2s           r�_div2n1nrh�s���	�|�|�~���Z�'��a�|��
�a�%�C�
�	�a���	�a���	�Q���
�!�V�F�
��K�1��D�
�[�!�(���Q�V�a�k�T�1�1�"�E�E�B��Q�D��!��4�E�B�
�	�a���
�<�"��a��rc��X-	U:XaSU-S-
XU--
U-pvO[XU5upgXu-U-Xd--
nUS:aUS-nXr-
nUS:aMXg4$)zAHelper function for _div2n1n; not intended to be called directly.rr)rh)�a12�a3rKrcrdr#�qrfs        rr_r_sn��
�x�2�~��Q��!�|�S�!�G�_�r�1�1����#���	
��"�����A�
�a�%�	�Q���	����a�%�
�4�Krc�^^^�S/UR5T-S-
T--mUUU4SjmU(aT"US[T55 T$)a2Decompose non-negative int a into base 2**n

Input:
  a is a non-negative integer

Output:
  List of the digits of a in base 2**n in little-endian order,
  meaning the most significant digit is last. The most
  significant digit is guaranteed to be non-zero.
  If a is 0 then the output is an empty list.

rrc�z>�US-U:XaUTU'gX-S-	nX1-
T	-nX-	nXU--nT"XaU5 T"XSU5 gr!r")
�x�L�RrL�shift�upper�lower�a_digitsr'r#s
       ���rr'�_int2digits.<locals>.inner.sW����q�5�A�:��H�Q�K���u��l����A�
���
���e�^�$��
�e���
�e�!�r)r.rO)rJr#rur's `@@r�_int2digitsrwsE����s�q�|�|�~��)�A�-�!�3�4�H�	�	�
�a��C��M�"��Orc�N^^^�UUU4SjmT(aT"S[T55$S$)zxCombine base-2**n digits into an int. This function is the
inverse of `_int2digits`. For more details, see _int2digits.
c�d>�US-U:XaTU$X-S-	nX -
T-nT"X!5U-T"X5-$r!r")rprqrLrr�digitsr'r#s    ���rr'�_digits2int.<locals>.innerCsF����q�5�A�:��!�9���u��l����A�
���c�
��&�%��-�7�7rr)rO)rzr#r's``@r�_digits2intr|>s"���
8�%+�5��C��K� �1��1rc���UR5n[X5nSn/n[U5H'n[XB-U-X5uptUR	U5 M) UR5 [
XR5nX�4$)zWDivide a non-negative integer a by a positive integer b, giving
quotient and remainder.r)r.rw�reversedrh�append�reverser|)	rJrKr#rurf�q_digits�a_digit�q_digitrls	         r�_divmod_posr�Msr��	
����A��1� �H�	�A��H��H�%���q�v��0�!�7�
������ �&�
�����H� �A��4�Krc��US:Xa[eUS:a[U*U*5up#X#*4$US:a[U)U5up#U)X)-4$[X5$)zyAsymptotically fast replacement for divmod, for 'int'.
Its time complexity is O(n**1.58), where n = #bits(a) + #bits(b).
r)�ZeroDivisionError�
int_divmodr�)rJrKrlrfs    rr�r�^se��	�A�v���	
�Q���1�"�q�b�!����"�u��	
�Q���1�"�a� ����r�1�r�6�z���1� � r)F)�__doc__rWr+r?�ImportErrorr�
getcontext�copyr-�MAX_PREC�prec�MAX_EMAX�Emax�MIN_EMIN�Emin�traps�Inexactr2rGrPrUr\r^rhr_rwr|r�r�r"rr�<module>r�s���>�
����B,
�\!�+�+�-�2�2�4��%�.�.���%�.�.���%�.�.���01����W�_�_�-�%�N+�Z�6 �	
�"�
� �<
��>2��"
!��W
���H��s�B$�$B/�.B/

?>