-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathFactorial.cpp
More file actions
26 lines (24 loc) · 753 Bytes
/
Factorial.cpp
File metadata and controls
26 lines (24 loc) · 753 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
#include <iostream>
#include "BigFloat.h"
BigFloat factorial(const BigFloat& n)
{
if(n > 1)
return n * factorial(n - 1);
else if(n == 0)
return 1;
else
return n;
}
int main()
{
//For reference, execution times on an old Core 2 Duo
//200! --> 375 digits - no optimization: 5 seconds
//300! --> 615 digits - no optimization: 20 seconds, compiled with -O3: 1 seconds
//500! --> 1135 digits - no optimization: 115 seconds, compiled with -O3: 4 seconds
//1000! --> 2568 digits - no optimization: 1200 seconds, compiled with -O3: 47 seconds
BigFloat fact, num(1000);
fact = factorial(num);
std::cout << fact << std::endl;
std::cout << fact.Ints() << std::endl;
return 0;
}