You are here

Long integers

4 September, 2015 - 14:38

If you compute fibonacci(50), you get:

>>> fibonacci(50)
12586269025L

The L at the end indicates that the result is a long integer, or type long. In Python 3, long is gone; all integers, even really big ones, are type int.

Values with type int have a limited range; long integers can be arbitrarily big, but as they get bigger they consume more space and time.

The mathematical operators work on long integers, and the functions in the math module, too, so in general any code that works with int will also work with long.

Any time the result of a computation is too big to be represented with an integer, Python converts the result as a long integer:

>>> 1000 * 10001000000>>> 100000 * 10000010000000000L

In the first case the result has type int; in the second case it is long.

Exercise 11.8.Exponentiation of large integers is the basis of common algorithms for public-key encryption. Read the Wikipedia page on the RSA algorithm (https://en.wikipedia.org/wiki/RSA_(algorithm)​ ) and write functions to encode and decode messages.