Sep-14-2019, 11:26 AM
(Sep-10-2019, 07:20 AM)DeaD_EyE Wrote: I have to look in my Math-book. Maybe there is a solution: http://weitz.de/KMFI/
The book is good, but it's only in German. He uses Python to explain math.
With modular arithmetic you get the last x digits of the solution.
The built-in functionpow
supports it.
The equation is: 2 ** (2 ** 34)
pow(2, 2**34, 10**12)This should calculate the last 12 digits of 2 ** (2**34)
The other solution to get the first x digits can may be done with iteration.
def ipow(x, y, digits): for _ in range(y - 1): x *= x # do something to truncate x? # maybe working with math.log10By the way, this question is very old: https://stackoverflow.com/questions/6351...e-required
Another solution is the usage of math.log10: https://stackoverflow.com/questions/3873...nentiation
def get_first_digits(a, b, n): x = b * math.log10(a) y = math.floor(pow(10, x - math.floor(x) + n - 1)) return int(y)
Output:In [65]: get_first_digits(2,2**34,12) Out[65]: 927436539881
I showed these numbers yesterday to my teacher and he said they are not the correct ones. I have to buy a virtual machine soon to see the full number...