diff --git a/.verify-helper/docs/static/notebook.html b/.verify-helper/docs/static/notebook.html index 7dd8abe..75e82f8 100644 --- a/.verify-helper/docs/static/notebook.html +++ b/.verify-helper/docs/static/notebook.html @@ -37,6 +37,7 @@

ICPC Notebook

  • math
    1. +
    2. BinaryGCD.hpp
  • modint
    1. @@ -223,6 +224,26 @@

      FastSet.hpp

      math

      +
      +

      BinaryGCD.hpp

      + md5: f3ab31 + +
      +
      +
      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);
      +}
      +
      +
      +

      modint

      @@ -663,16 +684,6 @@

      高度合成数

      768 1344 - -factor -3111 -3311 -33111 -421111 -631111 -5311111 -6321111 - @@ -684,6 +695,9 @@

      高度合成数

      + + + @@ -694,37 +708,65 @@

      高度合成数

      - - - - - - - - - + + +
      $10^{13}$ $10^{14}$ $10^{15}$$10^{16}$$10^{17}$$10^{18}$
      10752 17280 26880
      factor532111116322111164211111163211111115422111111642111111114147264512103680
      +

      素数階乗

      - - - - + + + + + + + + + + + - - - - + + + + + + + + + + + +
      $≤n$$10^{16}$$10^{17}$$10^{18}$$n$$2$$3$$5$$7$$11$$13$$17$$19$$23$$29$
      $d^0(x)$4147264512103680$n\#$26302102310300305105109699690$2.2 \times 10^8$$6.5 \times 10^9$
      +

      階乗

      + + - - - - + + + + + + + + + + + + + + + + + + +
      factor83221111111632211111111842211111111$5!$$6!$$7!$$8!$$9!$$10!$$11!$$12!$
      1207205040403203628803628800$4.0 \times 10^7$$4.8 \times 10^8$
      diff --git a/.verify-helper/docs/static/notebook.pdf b/.verify-helper/docs/static/notebook.pdf index 5835afe..da23eff 100644 Binary files a/.verify-helper/docs/static/notebook.pdf and b/.verify-helper/docs/static/notebook.pdf differ diff --git a/build/notebook.html b/build/notebook.html index e89d0ad..75e82f8 100644 --- a/build/notebook.html +++ b/build/notebook.html @@ -37,6 +37,7 @@

      ICPC Notebook

  • math
    1. +
    2. BinaryGCD.hpp
  • modint
    1. @@ -223,6 +224,26 @@

      FastSet.hpp

      math

      +
      +

      BinaryGCD.hpp

      + md5: f3ab31 + +
      +
      +
      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);
      +}
      +
      +
      +

      modint

      diff --git a/docs/math/BinaryGCD.md b/docs/math/BinaryGCD.md new file mode 100644 index 0000000..1c152c3 --- /dev/null +++ b/docs/math/BinaryGCD.md @@ -0,0 +1,11 @@ +--- +title: Binary GCD +documentation_of: //src/math/BinaryGCD.hpp +--- + +割り算を使わない高速な GCD + +## 使い方 + +- `u64 binary_gcd(u64 x, u64 y)`:$x$ と $y$ の最大公約数を計算する. + - $O(\log(x + y))$ 時間 diff --git a/docs/modint/BarrettReduction.md b/docs/modint/BarrettReduction.md index d5ab9a9..ffe4a3b 100644 --- a/docs/modint/BarrettReduction.md +++ b/docs/modint/BarrettReduction.md @@ -2,6 +2,7 @@ title: Barrett Reduction documentation_of: //src/modint/BarrettReduction.hpp --- +- 参考実装:[AC Library](https://github.com/atcoder/ac-library/blob/master/atcoder/internal_math.hpp) 同じ mod でたくさん計算するとき,剰余算を掛け算に変換して高速化する. @@ -9,7 +10,7 @@ documentation_of: //src/modint/BarrettReduction.hpp - `Barrett br(mod)`:Barrett Reduction を準備する. - 制約:`mod < 2^32` -- `br.mul(u64 a, u64 b)`:`a * b % mod` を計算する. +- `u64 br.mul(u64 a, u64 b)`:`a * b % mod` を計算する. - 制約:`a * b < 2^64` ## 仕組み diff --git a/docs/modint/modint.md b/docs/modint/modint.md index ad52253..bafb6c0 100644 --- a/docs/modint/modint.md +++ b/docs/modint/modint.md @@ -2,6 +2,7 @@ title: Modint documentation_of: //src/modint/modint.hpp --- +- 参考実装:[AC Library (初期実装)](https://github.com/atcoder/ac-library/blob/8250de484ae0ab597391db58040a602e0dc1a419/atcoder/convolution.hpp) - タイプ速度重視の簡易 modint - 速度が欲しいとき:[32 bit で加減算をちゃんと書いた Modint](../extra/modint_fast.hpp) diff --git a/notebook.pdf b/notebook.pdf index 5a5d08f..da23eff 100644 Binary files a/notebook.pdf and b/notebook.pdf differ diff --git a/src/math/FastGCD.hpp b/src/math/BinaryGCD.hpp similarity index 100% rename from src/math/FastGCD.hpp rename to src/math/BinaryGCD.hpp diff --git a/test/math/FastGCD.test.cpp b/test/math/BinaryGCD.test.cpp similarity index 50% rename from test/math/FastGCD.test.cpp rename to test/math/BinaryGCD.test.cpp index a9fc9f1..a77f256 100644 --- a/test/math/FastGCD.test.cpp +++ b/test/math/BinaryGCD.test.cpp @@ -1,13 +1,15 @@ #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" +#include "src/math/BinaryGCD.hpp" int main() { mt19937_64 rnd; - rep(i, 0, (ll)1e7) { - u64 a = rnd(), b = rnd(); - assert(gcd(a, b) == binary_gcd(a, b)); + rep(shift, 0, 64) { + rep(i, 0, (ll)1e5) { + u64 a = rnd() >> shift, b = rnd() >> shift; + assert(gcd(a, b) == binary_gcd(a, b)); + } } puts("Hello World"); }