-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem 20
More file actions
38 lines (34 loc) · 931 Bytes
/
Copy pathproblem 20
File metadata and controls
38 lines (34 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*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!
*/
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<math.h>
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include<boost/lexical_cast.hpp>
using namespace std;
using boost::multiprecision::cpp_int;
cpp_int Factorial(int number)
{
cpp_int num = 1;
for (int i = 1; i <= number; i++)
num = num * i;
return num;
}
int main()
{ int result = 0;
int number = 100;
cpp_int fact = Factorial(number);
string factorial = boost::lexical_cast<string>(fact);
//cout << factorial + 1 <<endl;
for(char x : factorial){
result += stoi(&x);
}
cout << result <<endl;
return 0;
}