Skip to content

Instantly share code, notes, and snippets.

View dgr8singh's full-sized avatar

Ankit Singh dgr8singh

  • Nit Kuruskhetra
View GitHub Profile
@Jangwa
Jangwa / nCr With MOD.cpp
Last active July 12, 2020 13:31
For larger factorials you can either write big factorial library or use a language like Python. The time complexity is O(n). If we have to calcuate nCr mod p(where p is a prime), we can calculate factorial mod p and then use modular inverse to find nCr mod p. If we have to find nCr mod m(where m is not prime), we can factorize m into primes and …
#include<iostream>
using namespace std;
#include<vector>
/* This function calculates (a^b)%MOD */
long long pow(int a, int b, int MOD)
{
long long x=1,y=a;
while(b > 0)
{