Problem 020


Project Euler

Factorial digit sum

Problem 20

n! means n × (n − 1) × … × 3 × 2 × 1

For example, 10! = 10 × 9 × … × 3 × 2 × 1 = 3628800,
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.

Find the sum of the digits in the number 100!


This problem is similar to problem 16 where the interim result may has many digits so each multiplication must be done carefully using array of integer (or char) to avoid overflow. The idea is essentially the same with any big number problem, use carry and multiply (or add) each digit in sequence for each calculation. Problem 13, 16 and 20, seems to be the solutions for building a big integer library.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s