Hello, codeforces
I write a personal C++ template for Competitive Programming Algorithms. It contains many common algorithms, especially mathematical ones.
I know that the more you use it, the more reliable it is. Almost all template are tested in a Chinese OJ: LuoGu. However, no one can ensure that no bugs in their codes.
Thanks in advance if you find some bugs or give other testes.
As we know, programmers hate two things:
- writing documents
- others who don't writing documents
Here is Document and Source Code for detail.
As an example, you can solve $$$n! \mod p$$$ in SPOJ where $$$0 < n, p < 10^{11}$$$, use following simple code.
#include <bits/stdc++.h>
#define clog(x) std::clog << (#x) << " is " << (x) << '\n';
using LL = long long;
#include "../cpplib/math.hpp"
// https://www.spoj.com/problems/FACTMODP/en/
int main() {
// freopen("in", "r", stdin);
std::cin.tie(nullptr)->sync_with_stdio(false);
int cas = 1;
std::cin >> cas;
while (cas--) {
LL n, p;
std::cin >> n >> p;
std::cout << factorial(n, p) << '\n';
}
return 0;
}
my submission contains 925 lines after copy some codes from math.hpp
UDP: The document for math.hpp
have been enhanced with the help of kpw29's advice.
UDP2: non-const member variables terminate with _
, and std::move, std::forward
are used.