Skip to content

Instantly share code, notes, and snippets.

@zorchp
Created May 19, 2023 04:10
Show Gist options
  • Save zorchp/da1ae8c78932b8e910c57505be5a9294 to your computer and use it in GitHub Desktop.
Save zorchp/da1ae8c78932b8e910c57505be5a9294 to your computer and use it in GitHub Desktop.
some useful math function written by C++.
// calc factorial
auto f=[](int n) {
int ans{1};
while (n > 1) ans*= n, --n;
return ans;
};
// calc combination number
auto comb = [](int n, int k) {
int ans{1};
for (int i{}; i < k; ++i) ans = ans * (n - i) / (i + 1); // can not `ans *= `
return ans;
};
function<int(int, int)> gcd = [&](int a, int b) {
return b ? gcd(b, a % b) : a;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment