简体   繁体   中英

Printing of large numbers as Strings/ Running a loop for 10 power 100,000

In solving a question related to permutations and probability, I have got stuck at the following problem, where I need to print the reciprocal of a number and the range of the number can go up to 10 10 5 .

Possible Approach which I looked into for printing that number is: -Using own java class/BigInteger as per following ques :

How to handle very large numbers in Java without using java.math.BigInteger

But the limitation is, it still cannot cater to the limit required.

I also looked for another approach but that was in python. For example, following logic in python works fine:

x=int(input()) print x*'0'

If the input is 100000 then the output is : 100000 times 0 written in the console.

What is some other good approach to solve the given issue?

Thanks in Advance.

I once had to do something similar, it's a real pain. What I ended up doing was representing the massive number into multiple BigIntegers, and storing the parts in a linked list. Hope this has the potential to help.

There is a variety of ways you can solve this and store super large numbers- you can use multiple BigIntegers to store parts of them. Or like you can create your own data structure and wrapper.

class LargeNumber{
   Integer base;
   Integer power;
   LargeNumber(Integer base, Integer power){
      this.base = base; 
      this.power = power;
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM