diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 98e13e0..199f5ce 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -29,6 +29,7 @@ jobs: path: | .verify-helper/cache/ ~/.cache/online-judge-tools/library-checker-problems/ + ~/.local/share/online-judge-tools/ key: cache-judge-data - name: Run tests diff --git a/src/math/FastGCD.hpp b/src/math/FastGCD.hpp new file mode 100644 index 0000000..63953ef --- /dev/null +++ b/src/math/FastGCD.hpp @@ -0,0 +1,11 @@ +u64 ctz(u64 x) { return countr_zero(x); } +u64 binary_gcd(u64 x, u64 y) { + if(!x || !y) return x | y; + u64 n = ctz(x), m = ctz(y); + x >>= n, y >>= m; + while(x != y) { + if(x > y) x = (x - y) >> ctz(x - y); + else y = (y - x) >> ctz(y - x); + } + return x << min(n, m); +} diff --git a/test/math/FastGCD.test.cpp b/test/math/FastGCD.test.cpp new file mode 100644 index 0000000..a9fc9f1 --- /dev/null +++ b/test/math/FastGCD.test.cpp @@ -0,0 +1,13 @@ +#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A" +#include "test/template.hpp" +using u64 = uint64_t; +#include "src/math/FastGCD.hpp" + +int main() { + mt19937_64 rnd; + rep(i, 0, (ll)1e7) { + u64 a = rnd(), b = rnd(); + assert(gcd(a, b) == binary_gcd(a, b)); + } + puts("Hello World"); +} diff --git a/test/template.test.cpp b/test/template.test.cpp index fff0ab8..e19b30e 100644 --- a/test/template.test.cpp +++ b/test/template.test.cpp @@ -7,5 +7,5 @@ int main() { assert(chmax(a, 1) == 1); assert(chmax(a, 1) == 0); assert(chmin(a, 0) == 1); - cout << "Hello World" << endl; + puts("Hello World"); }