Created
May 19, 2023 04:10
-
-
Save zorchp/da1ae8c78932b8e910c57505be5a9294 to your computer and use it in GitHub Desktop.
some useful math function written by C++.
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
// 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