使用Java中的节点计算大阶乘 [英] Calculate Large Factorials Using Nodes in Java

查看:119
本文介绍了使用Java中的节点计算大阶乘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我一直在互联网上搜索,发现了许多与此问题有关的东西.但是,我无法将各个部分放在一起以弄清楚这一点.

Okay, so I have been searching the internet and have found many things related to this question. However, I am not able to put the pieces together in order to figure this out.

要求是使用链接列表和节点来计算较大的阶乘(例如999!).在线上有很多人展示了计算阶乘的基本方法,我了解如何执行阶乘部分,但是我遇到问题的部分是用0-999(三位数字)之间的整数填充每个节点.然后打印出每个节点,使其看起来像一个整数(包括逗号).

The requirements are to calculate a large factorial (e.g. 999!) USING LINKED LISTS and NODES. There are many people online that have shown a basic way of calculating a factorial and I understand how to do the factorial part, but the part I am having trouble with is filling each node with an Int between 0-999 (a three digit number) then printing out each node to look like a whole number (including commas).

我该如何实现? -我的想法是得到n的结果!只需执行%10,%100等将其分解并将其插入节点中即可,但这将是没有意义的,因为阶乘必须完全解决才能正常工作.这样太蠢了.

How can I achieve this? - My thoughts are to get the result of n! and just do %10, %100,etc.. to break it up and insert the parts into nodes, but that would be pointless because the factorial would have to be completely solved for that to work. So that would be dumb.

这样做的原因是学习如何为我的Data Structures类操纵节点和链接列表.

The reason for doing this is to learn how to manipulate nodes and linked lists for my Data Structures class.

对我来说,这是一个清晰的解释,但是如果问题不清楚,请让我知道,我会尽力解释.任何帮助将不胜感激.

To me, this a clear explanation, but please let me know if the question is unclear and I will try to explain. Any help will be much appreciated.

(除了我要用作基础的基本阶乘函数之外,我没有任何代码可显示).

(I dont have any code to show besides a basic factorial function that I am using as a bases to build upon).

推荐答案

好的,我想我明白你的追求.

Okay, I think I understand what you're after.

此答案的末尾是指向Gist的链接,该链接可解决此问题.我不完全确定这是您的追求,a,这是我的最佳猜测.

At the end of this answer is a link to a Gist that solves this problem. I'm not entirely sure it's what you are after, alas... it's my best guess.

该算法包括五个步骤:

  1. 建立阶乘成员列表.
  2. 计算并分组阶乘成员的主要因子.
  3. 根据10的幂分配素因.
  4. 乘以素数,将溢出向上累加到下一个小数 地方.
  5. 打印解决方案.
  1. Build the list of factorial members.
  2. Calculate and group Prime Factors of factorial members.
  3. Distribute Prime Factors over powers of 10.
  4. Multiply Prime Factors, carrying overflow up into the next decimal place.
  5. Print the solution.

它受到此处math.stackexchange.com 所述方法的启发.我强烈建议您在检查要点之前先阅读所链接的问题和答案.

It is inspired by the method described here on math.stackexchange.com. I strongly suggest reading both the question and answer linked before examining the Gist.

现在已经说过了,要旨可以在此处找到.这非常粗糙,仅是对该方法的快速演示.

Now that that's been said, the Gist can be found here. It is very rough, meant only as a quick demonstration of the method.

我希望它能对您有所帮助.祝你好运.

I hope it helps you. Best of luck.

这篇关于使用Java中的节点计算大阶乘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆