阶乘函数java,使用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.

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).

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.

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.

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.

The algorithm consists of five steps:

Build the list of factorial members.

Calculate and group Prime Factors of factorial members.

Distribute Prime Factors over powers of 10.

Multiply Prime Factors, carrying overflow up into the next decimal

place.

Print the solution.

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值