Skip to content

Instantly share code, notes, and snippets.

@DarkStar1997
Created March 23, 2018 20:09
Show Gist options
  • Save DarkStar1997/678140c5185f1a9e52f179dc11f5db01 to your computer and use it in GitHub Desktop.
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
#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