OverflowError: math range error

for i in range(len(out_text_2)-1):
      if i==0:
            out_text_2[i]=str(out_text_2[i])
      else:
           out_text_2[i]=str(int(int(out_text_2[i]1])+int(out_text_2[i]))%N) 
for i in range(len(out_text_2)-1):
           out_text_2[i]=str(int(pow(int(out_text_2[i]),e))%N)

The program can not perform mathematical calculations, because the response results in huge numbers.

Author: Pavel Durmanov, 2017-03-26

1 answers

When working with very large numbers, the standard types are not enough. You need to use the module decimal.

For example, this code throws an exception OverflowError: math range error:

from math import *
val = '9' * 200
print(pow(int(val), e))

You need to rewrite it like this:

import decimal
from math import *
val = '9' * 200
# Указываем, сколько знаков после запятой (необязательно)
decimal.getcontext().prec = 50  
print(decimal.Decimal(val) ** decimal.Decimal(e))

Output:

4.5327909680335543398973100746569134091462672506017E+543
 1
Author: Кирилл Малышев, 2017-03-26 15:59:27