Recently I started being very fascinated in logistics, and out of the blue came the question into my head, what is the factorial of the amount of atoms in the observeable universe, which is said to be between 1,e+78
and 1,e+82
but the amount of ways you can arrange these atoms is unimaginably larger. So I played with this number and I thought it might be interesting to see how far I could get on calculating the factorial of 1,e+80
, so I went ahead and created a simple java program:
import java.awt.Color;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Factorial {
public static void main(String[] args) {
JFrame frame = new JFrame("Project Factorial");
frame.setAlwaysOnTop(true);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.setLocation(0, 0);
frame.setUndecorated(true);
JLabel label = new JLabel();
label.setForeground(Color.white);
frame.getContentPane().setBackground(Color.BLUE);
frame.getContentPane().add(label);
frame.setVisible(true);
BigDecimal atoms = new BigDecimal("1E+80");
BigDecimal total = new BigDecimal("1");
double increment = new BigDecimal("100.0").divide(atoms)
.doubleValue();
double percentage = increment;
for (BigDecimal num = new BigDecimal("2"); num.compareTo(atoms) <= 0; num
.add(BigDecimal.ONE)) {
total = total.multiply(num);
percentage += increment;
label.setText("[" + String.format("%-10.3f%%", percentage) + "]"
+ format(total, total.scale()));
frame.pack();
Thread.yield();
}
}
private static String format(BigDecimal x, int scale) {
NumberFormat formatter = new DecimalFormat("0.0E0");
formatter.setRoundingMode(RoundingMode.HALF_UP);
formatter.setMinimumFractionDigits(scale);
return formatter.format(x);
}
}
Quickly after running this program for about an hour I realized running this kind of calculation on any computer today would absolutely take ages, I was hopping to reach 0,001 % on the calculation but it is certainly too large to calculate, but then the question came up, exactly how long would it take? That question is not so easy to answer considering there is alot of factors involved, but really what I am trying to solve is the factorial of 1,e+80
.
$$(1\times10^{80})!$$
The number can be very hard to understand just how big it is, so I'd like to visualise how big that number is, for instance, if you could calculate how long it would take for a computer to calculate the factorial of 1,e+80
that would be a cool visualization.
(EDIT: Thanks for the great answers, however, I wish to implement a way of calculating the factorial of 1,e+80
in a application despite I would need to use some kind of approximation formula, so I decided to use Stirling's approximation based on derpy's answer.
$$n! \sim \sqrt{2\pi n}\left(\frac{n}{e}\right)^n$$
So with Stirling's approximation and GMP library for C programming language it would be possible to make a quite accurate and efficient program to calculate the factorial of 1,e+80
)