Python Forum
how do I show 12 numbers from a huge number?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how do I show 12 numbers from a huge number?
#30
(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 function pow 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.log10 
By 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

Thank you, I will show 927436539881 to my teacher and then you will know his answer
Reply


Messages In This Thread
RE: how do I show 12 numbers from a huge number? - by anabeatriz - Sep-10-2019, 08:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Random Generator: From Word to Numbers, from Numbers to n possibles Words Yamiyozx 2 1,526 Jan-02-2023, 05:08 PM
Last Post: deanhystad
  Convert list of numbers to string of numbers kam_uk 5 3,134 Nov-21-2020, 03:10 PM
Last Post: deanhystad
  Divide a number - Multiple levels - Sum of all numbers equal to input number pythoneer 17 9,053 Apr-20-2018, 04:07 AM
Last Post: pythoneer
  Trying to get the week number from a string of numbers fad3r 2 3,301 Apr-15-2018, 06:52 PM
Last Post: ljmetzger
  Regular Expressions in Files (find all phone numbers and credit card numbers) Amirsalar 2 4,188 Dec-05-2017, 09:48 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020