Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,722 members, 7,809,740 topics. Date: Friday, 26 April 2024 at 02:09 PM

What Does 1 Million Factorial Look Like? - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / What Does 1 Million Factorial Look Like? (1484 Views)

How My Learning Path Would Look Like When Im Ready To Start Learning To Code / What Does It Entail To Be A Back-end Developer? / What Does 1 Million Factorial Look Like? (2) (3) (4)

(1) (Reply) (Go Down)

What Does 1 Million Factorial Look Like? by abumeinben(m): 7:51am On Apr 14, 2019
Hello geeks,

I'm learning some Java coding and I decided to hit on factorial of numbers.

I'll drop the code and also the factorial for 1000, 2000, ......30000.

1000000! can crash you PC grin due to the size and time it takes to run.

Let's start with the code:

class Factorial {

public static void main(String[] args) {
System.out.print("Enter value for factorial: " );
Scanner input = new Scanner(System.in);
int value = input.nextInt();
System.out.println(value + "! is " + factorial(value));

System.out.println("Digit count is " + count(factorial(value)));
}

static long count(BigInteger k){ //Count all digits
double factor = Math.log(2)/Math.log(10);
int count = (int)(factor*k.bitLength()+1);
if(BigInteger.TEN.pow(count-1).compareTo(k)>0){
return count-1;
}
return count;
}
public static BigInteger factorial(long n) {//compute factorial
BigInteger result = BigInteger.ONE;
for (int i = 1; i <= n; i++)
result = result.multiply(new BigInteger(i+"" ));

return result;
}
}
Re: What Does 1 Million Factorial Look Like? by abumeinben(m): 7:51am On Apr 14, 2019
1000

3000
Re: What Does 1 Million Factorial Look Like? by abumeinben(m): 7:52am On Apr 14, 2019
9000!

Enter value for factorial: 9000
9000! is ..........0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Digit count is 31682


Common 9000 factorial, nairaland complained of post being too long. The zeros are the last digits

Re: What Does 1 Million Factorial Look Like? by abumeinben(m): 7:52am On Apr 14, 2019
11-20000
Re: What Does 1 Million Factorial Look Like? by abumeinben(m): 7:53am On Apr 14, 2019
30000
Re: What Does 1 Million Factorial Look Like? by abumeinben(m): 7:53am On Apr 14, 2019
100000
Re: What Does 1 Million Factorial Look Like? by Olalekank(m): 10:50am On Apr 14, 2019
Good one

Did you use the multiplication method of 1 * 2 * 3... or you used recursion method?

If you use recursive method, it would take a shorter time to run compared to multiplying
Re: What Does 1 Million Factorial Look Like? by abumeinben(m): 4:54pm On Apr 26, 2019
Olalekank:
Good one

Did you use the multiplication method of 1 * 2 * 3... or you used recursion method?

If you use recursive method, it would take a shorter time to run compared to multiplying

A program in Java was used.
Re: What Does 1 Million Factorial Look Like? by Superstar007(m): 6:38pm On Apr 26, 2019
integer overflow.
Re: What Does 1 Million Factorial Look Like? by Nobody: 8:03am On Apr 28, 2019
Do it recursively
Re: What Does 1 Million Factorial Look Like? by abumeinben(m): 4:07pm On May 02, 2019
Superstar007:
integer overflow.

yes if you used integers. I used BigInetgers, however.

Would drop the code as well


Edit:

Code added to post

(1) (Reply)

Building A Payment App / Please How Can I Start Getting Jobs Or Clients As A Website Designer / Hoiw Can I Mod Java Application

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 12
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.