From 7f6a4e3271329554151cce678240218b19f09ab4 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 17 Nov 2022 10:43:30 +0800 Subject: [PATCH] =?UTF-8?q?#6257.=20=E3=80=8CCodePlus=202017=2012=20?= =?UTF-8?q?=E6=9C=88=E8=B5=9B=E3=80=8D=E5=8F=AF=E5=81=9A=E9=A2=982?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://loj.ac/s/1634472 --- LibreOJ/6257/6257.cpp | 120 +++++++++++++++++++++++++++++++++++++++ LibreOJ/6257/data/1.ans | 3 + LibreOJ/6257/data/1.in | 3 + LibreOJ/6257/data/10.ans | 3 + LibreOJ/6257/data/10.in | 3 + LibreOJ/6257/data/2.ans | 3 + LibreOJ/6257/data/2.in | 3 + LibreOJ/6257/data/3.ans | 3 + LibreOJ/6257/data/3.in | 3 + LibreOJ/6257/data/4.ans | 3 + LibreOJ/6257/data/4.in | 3 + LibreOJ/6257/data/5.ans | 3 + LibreOJ/6257/data/5.in | 3 + LibreOJ/6257/data/6.ans | 3 + LibreOJ/6257/data/6.in | 3 + LibreOJ/6257/data/7.ans | 3 + LibreOJ/6257/data/7.in | 3 + LibreOJ/6257/data/8.ans | 3 + LibreOJ/6257/data/8.in | 3 + LibreOJ/6257/data/9.ans | 3 + LibreOJ/6257/data/9.in | 3 + 21 files changed, 180 insertions(+) create mode 100644 LibreOJ/6257/6257.cpp create mode 100644 LibreOJ/6257/data/1.ans create mode 100644 LibreOJ/6257/data/1.in create mode 100644 LibreOJ/6257/data/10.ans create mode 100644 LibreOJ/6257/data/10.in create mode 100644 LibreOJ/6257/data/2.ans create mode 100644 LibreOJ/6257/data/2.in create mode 100644 LibreOJ/6257/data/3.ans create mode 100644 LibreOJ/6257/data/3.in create mode 100644 LibreOJ/6257/data/4.ans create mode 100644 LibreOJ/6257/data/4.in create mode 100644 LibreOJ/6257/data/5.ans create mode 100644 LibreOJ/6257/data/5.in create mode 100644 LibreOJ/6257/data/6.ans create mode 100644 LibreOJ/6257/data/6.in create mode 100644 LibreOJ/6257/data/7.ans create mode 100644 LibreOJ/6257/data/7.in create mode 100644 LibreOJ/6257/data/8.ans create mode 100644 LibreOJ/6257/data/8.in create mode 100644 LibreOJ/6257/data/9.ans create mode 100644 LibreOJ/6257/data/9.in diff --git a/LibreOJ/6257/6257.cpp b/LibreOJ/6257/6257.cpp new file mode 100644 index 00000000..87b95584 --- /dev/null +++ b/LibreOJ/6257/6257.cpp @@ -0,0 +1,120 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +class Matrix { + private: + long long data[10][10], mod; + + public: + Matrix(long long _mod = 1e9 + 7) + : mod(_mod) { + memset(data, 0x00, sizeof(data)); + } + + long long *operator[](long long i) { + return data[i]; + } + + Matrix operator*(Matrix b) const { + Matrix c(mod); + + int n = 2; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + for (int k = 1; k <= n; k++) { + c[i][j] = (c[i][j] + data[i][k] * b[k][j] % mod) % mod; + } + } + } + + return c; + } +}; + +Matrix binpow(Matrix a, long long k, long long p) { + Matrix res(p); + res[1][1] = 1; + res[1][2] = 1; + + while (k) { + if (k & 1) res = res * a; + a = a * a; + k >>= 1; + } + + return res; +} + +long long fib(long long n, long long p) { + if (n <= 2) { + return n != 0; + } + + Matrix tmp(p); + + tmp[1][1] = 1, tmp[1][2] = 1; + tmp[2][1] = 1, tmp[2][2] = 0; + + return binpow(tmp, n - 2, p)[1][1]; +} + +long long exgcd(long long a, long long b, long long &x, long long &y) { + if (!b) { + x = 1, y = 0; + return a; + } + + long long g = exgcd(b, a % b, y, x); + y -= a / b * x; + + return g; +} + +long long calc(long long x, long long y) { + if (x == 0) return 0; + + return x < 0 ? -(-x + y - 1) / y : x / y; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + int t; + + cin >> t; + + while (t--) { + long long i, l, r, k, p, m, x, y; + + cin >> i >> l >> r >> k >> p >> m; + + long long f1 = fib(k - 2, p), + f2 = fib(k - 1, p); + + long long a = f2, + b = p, + c = ((m - i % p * f1 % p) + p) % p, + g = std::__gcd(a, b); + + if (c % g) { + cout << 0 << endl; + + continue; + } + + a /= g, b /= g, c /= g; + exgcd(a, b, x, y); + x = (x * c % b + b) % b; + + cout << calc(r - x, b) - calc(l - x - 1, b) << endl; + } + + return 0; +} diff --git a/LibreOJ/6257/data/1.ans b/LibreOJ/6257/data/1.ans new file mode 100644 index 00000000..54f75571 --- /dev/null +++ b/LibreOJ/6257/data/1.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3334c2a6c46f1696ddbe00540db3c5325b79a98a038eefabd60227293571907e +size 21 diff --git a/LibreOJ/6257/data/1.in b/LibreOJ/6257/data/1.in new file mode 100644 index 00000000..819aa33d --- /dev/null +++ b/LibreOJ/6257/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5a16fa04aae1a19b2a71aaa866d97fa9342ed1296e26d5108c12207d01dbbdfb +size 334 diff --git a/LibreOJ/6257/data/10.ans b/LibreOJ/6257/data/10.ans new file mode 100644 index 00000000..daf9dffd --- /dev/null +++ b/LibreOJ/6257/data/10.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7f614474b5af9b754135b164a23f460742f553a096f96eb957f19e455206a993 +size 95 diff --git a/LibreOJ/6257/data/10.in b/LibreOJ/6257/data/10.in new file mode 100644 index 00000000..7f593be4 --- /dev/null +++ b/LibreOJ/6257/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6a1f965bb83e07c297d83a2b97a1cd5f5333bd12466a666bb94810a94ebe4757 +size 882 diff --git a/LibreOJ/6257/data/2.ans b/LibreOJ/6257/data/2.ans new file mode 100644 index 00000000..cc20ce8e --- /dev/null +++ b/LibreOJ/6257/data/2.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd7197855f455548d4c0df51d2c51e65d7baa15adc42aba29d8dc03a22771c5c +size 24 diff --git a/LibreOJ/6257/data/2.in b/LibreOJ/6257/data/2.in new file mode 100644 index 00000000..4da64037 --- /dev/null +++ b/LibreOJ/6257/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:32b608ef8e5e8aec38a7eefd2532a3f808f54bcf921d4ca7f9c167469407eb30 +size 430 diff --git a/LibreOJ/6257/data/3.ans b/LibreOJ/6257/data/3.ans new file mode 100644 index 00000000..788d8cd9 --- /dev/null +++ b/LibreOJ/6257/data/3.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6bfea701902fbb628aee44d8f945037610ecac6ae50aa4d90909e4508687777c +size 26 diff --git a/LibreOJ/6257/data/3.in b/LibreOJ/6257/data/3.in new file mode 100644 index 00000000..9bbfa4c6 --- /dev/null +++ b/LibreOJ/6257/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:28633ead5404e7d9c0afbf7ff5bc228709fb75976242511e225a7504317f4cbb +size 436 diff --git a/LibreOJ/6257/data/4.ans b/LibreOJ/6257/data/4.ans new file mode 100644 index 00000000..cbed4387 --- /dev/null +++ b/LibreOJ/6257/data/4.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c2afca3036354a597cccc4fae5e28ffc8267d1a08688018ca282393fd46827da +size 27 diff --git a/LibreOJ/6257/data/4.in b/LibreOJ/6257/data/4.in new file mode 100644 index 00000000..dba092c7 --- /dev/null +++ b/LibreOJ/6257/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f3e55f9dde0645c1284d8ee51eeef239dc84ae3613ca8ecdb38a38d066409ea8 +size 564 diff --git a/LibreOJ/6257/data/5.ans b/LibreOJ/6257/data/5.ans new file mode 100644 index 00000000..1a0d0470 --- /dev/null +++ b/LibreOJ/6257/data/5.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a3783b2b9be8a9af60cb4e574be5728e4e33c0c16fc841f243f73fd15297a5d +size 24 diff --git a/LibreOJ/6257/data/5.in b/LibreOJ/6257/data/5.in new file mode 100644 index 00000000..ad44210b --- /dev/null +++ b/LibreOJ/6257/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:edb3a11863aa4c2a8658388b675625488bd3be4fbe4fac0996b64e2cfa95eee7 +size 577 diff --git a/LibreOJ/6257/data/6.ans b/LibreOJ/6257/data/6.ans new file mode 100644 index 00000000..c3fa6120 --- /dev/null +++ b/LibreOJ/6257/data/6.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f05898afc831db172257d21fa28636044bb4ade8225e589dab80de96a7f81a60 +size 108 diff --git a/LibreOJ/6257/data/6.in b/LibreOJ/6257/data/6.in new file mode 100644 index 00000000..0a83f5bb --- /dev/null +++ b/LibreOJ/6257/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3ebf71373b220ca25a70ddfbb1c2e05187ea01840001207da318c56706a45952 +size 750 diff --git a/LibreOJ/6257/data/7.ans b/LibreOJ/6257/data/7.ans new file mode 100644 index 00000000..bfa06257 --- /dev/null +++ b/LibreOJ/6257/data/7.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7838fb6ca5e8c7ddc6a2e218a8c71ce33532928a396b898ef0476c10d7d50e6c +size 109 diff --git a/LibreOJ/6257/data/7.in b/LibreOJ/6257/data/7.in new file mode 100644 index 00000000..923da378 --- /dev/null +++ b/LibreOJ/6257/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8e4586126852c2325161858b8c95e5e81261ddd8c2826abf797be686aa13862e +size 754 diff --git a/LibreOJ/6257/data/8.ans b/LibreOJ/6257/data/8.ans new file mode 100644 index 00000000..b56252fc --- /dev/null +++ b/LibreOJ/6257/data/8.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bf0500abc125fd79c2584c4ef24adcbb9332e25ec39dbc0f7f3fda5ca4cb643b +size 107 diff --git a/LibreOJ/6257/data/8.in b/LibreOJ/6257/data/8.in new file mode 100644 index 00000000..a240adce --- /dev/null +++ b/LibreOJ/6257/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9f5ba411399aa8c2e79351eefb3723e8de4660f83f46dde39382d51c30c52dee +size 883 diff --git a/LibreOJ/6257/data/9.ans b/LibreOJ/6257/data/9.ans new file mode 100644 index 00000000..2ce397a3 --- /dev/null +++ b/LibreOJ/6257/data/9.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d60ab6e929c28e3eeb38c583866eceba981f8453adc4a5d26fee6e00c33dba40 +size 84 diff --git a/LibreOJ/6257/data/9.in b/LibreOJ/6257/data/9.in new file mode 100644 index 00000000..5ea402bd --- /dev/null +++ b/LibreOJ/6257/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7fe98bb76960899a906f3cf7ec49ac5bb112225bb31789b14beb46e2ef4f195b +size 883