Project Euler Homework
|
Find the sum of digits in 100! More...
#include <iostream>
Go to the source code of this file.
Classes | |
class | bigN |
Functions | |
int | main () |
Compute factorial of a big number. | |
Variables | |
const unsigned long long | digits = 1e17 |
const int | gps = 10 |
Find the sum of digits in 100!
n! means n = (n - 1) * ... * 3 * 2 * 1 Find the sum of the digits in the number 100!
Definition in file 020.cpp.
int main | ( | ) |
Compute factorial of a big number.
C++ types: unsigned
long: up to 2^32-1 ~ 10^9.63
unsigned
long long: up to 2^64-1 ~ 10^19.27
Using estimation formula,
which has 158 digits, it is split to a number of segments in order to be processed by C++.
Let x be the number in one segment,
each segments should contains at most 17 digits.
So there are a total of segments.
Multiply each segments from 1 to 100, in each step raise the "carry" digits to next segments.