简体   繁体   English

以字符串形式打印大量数字/循环运行10次幂100,000

[英]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 . 在解决与置换和概率有关的问题时,我陷入了以下问题,我需要打印一个数字的倒数,并且这个数字的范围可以达到10 10 5

Possible Approach which I looked into for printing that number is: -Using own java class/BigInteger as per following ques : 我研究用于打印该数字的可能方法是:-按照以下问题使用自己的java类/ BigInteger:

How to handle very large numbers in Java without using java.math.BigInteger 如何在不使用java.math.BigInteger的情况下使用Java处理非常大的数字

But the limitation is, it still cannot cater to the limit required. 但是限制是,它仍然不能满足所需的限制。

I also looked for another approach but that was in python. 我也正在寻找另一种方法,但这是在python中。 For example, following logic in python works fine: 例如,在python中执行以下逻辑可以正常工作:

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

If the input is 100000 then the output is : 100000 times 0 written in the console. 如果输入为100000,则输出为:100000乘以0写入控制台。

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. 我最终要做的是将大量数字表示为多个BigInteger,并将零件存储在链接列表中。 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. 您可以通过多种方式解决此问题并存储超大数字-您可以使用多个BigInteger存储其中的一部分。 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;
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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