Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

pow large numbers in Python

How can I raise large numbers to a power in python?

a = 62608558862573792084872798679396455703616395237802859621162736207631538899993
b = 93910650126758265671774994856253142403789359314618444886584691522424141933664
c = pow(a, b)

It is impossible to get an answer that way. Are there any ways to raise large numbers to a power to make it work?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you calculate the result to all digits, it has 10^78 digits. That’s more than will fit into any RAM of any computer in the world today.

It is impossible to get an answer that way.

It will be impossible to get a precise answer for a long time, given that Earth only has ~10^50 atoms.

The number 62608558862573792084872798679396455703616395237802859621162736207631538899993 looks like a pseudo prime number (is has only 5 prime factors) as used in cryptography. Cryptography often works with modulo operations to limit the number of digits. You can use pow to do modulo math as well:

pow(base, exp, mod=None)

Return base to the power exp; if mod is present, return base to the power exp, modulo mod (computed more efficiently than pow(base, exp) % mod).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading