Created
March 23, 2018 20:09
-
-
Save DarkStar1997/678140c5185f1a9e52f179dc11f5db01 to your computer and use it in GitHub Desktop.
Calculating factorial manually (naively by running a loop) using GMP C++ Class Interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <gmpxx.h> | |
#include <chrono> | |
using namespace std; | |
int main() | |
{ | |
int n; cin>>n; | |
auto start=chrono::high_resolution_clock::now(); | |
mpz_class a=1; | |
for(int i=2; i<=n; i++) | |
a=a*i; | |
cout<<a<<"\n"; | |
auto end=chrono::high_resolution_clock::now(); | |
chrono::duration<double> diff=end-start; | |
cout<<"Time taken="<<diff.count()<<"s\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment