QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#395087 | #2115. Od deski do deski [A] | hos_lyric | 10 ✓ | 14ms | 4432kb | C++14 | 15.4kb | 2024-04-21 03:34:56 | 2024-04-21 03:34:56 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
static constexpr unsigned M = M_;
unsigned x;
constexpr ModInt() : x(0U) {}
constexpr ModInt(unsigned x_) : x(x_ % M) {}
constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
ModInt pow(long long e) const {
if (e < 0) return inv().pow(-e);
ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModInt inv() const {
unsigned a = M, b = x; int y = 0, z = 1;
for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
assert(a == 1U); return ModInt(y);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModInt &a) const { return (x == a.x); }
bool operator!=(const ModInt &a) const { return (x != a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////
constexpr unsigned MO = 1000000007;
using Mint = ModInt<MO>;
constexpr int LIM_INV = 1'000'010;
Mint inv[LIM_INV], fac[LIM_INV], invFac[LIM_INV];
void prepare() {
inv[1] = 1;
for (int i = 2; i < LIM_INV; ++i) {
inv[i] = -((Mint::M / i) * inv[Mint::M % i]);
}
fac[0] = invFac[0] = 1;
for (int i = 1; i < LIM_INV; ++i) {
fac[i] = fac[i - 1] * i;
invFac[i] = invFac[i - 1] * inv[i];
}
}
Mint binom(Int n, Int k) {
if (n < 0) {
if (k >= 0) {
return ((k & 1) ? -1 : +1) * binom(-n + k - 1, k);
} else if (n - k >= 0) {
return (((n - k) & 1) ? -1 : +1) * binom(-k - 1, n - k);
} else {
return 0;
}
} else {
if (0 <= k && k <= n) {
assert(n < LIM_INV);
return fac[n] * invFac[k] * invFac[n - k];
} else {
return 0;
}
}
}
////////////////////////////////////////////////////////////////////////////////
// M: prime, G: primitive root, 2^K | M - 1
template <unsigned M_, unsigned G_, int K_> struct Fft {
static_assert(2U <= M_, "Fft: 2 <= M must hold.");
static_assert(M_ < 1U << 30, "Fft: M < 2^30 must hold.");
static_assert(1 <= K_, "Fft: 1 <= K must hold.");
static_assert(K_ < 30, "Fft: K < 30 must hold.");
static_assert(!((M_ - 1U) & ((1U << K_) - 1U)), "Fft: 2^K | M - 1 must hold.");
static constexpr unsigned M = M_;
static constexpr unsigned M2 = 2U * M_;
static constexpr unsigned G = G_;
static constexpr int K = K_;
ModInt<M> FFT_ROOTS[K + 1], INV_FFT_ROOTS[K + 1];
ModInt<M> FFT_RATIOS[K], INV_FFT_RATIOS[K];
Fft() {
const ModInt<M> g(G);
for (int k = 0; k <= K; ++k) {
FFT_ROOTS[k] = g.pow((M - 1U) >> k);
INV_FFT_ROOTS[k] = FFT_ROOTS[k].inv();
}
for (int k = 0; k <= K - 2; ++k) {
FFT_RATIOS[k] = -g.pow(3U * ((M - 1U) >> (k + 2)));
INV_FFT_RATIOS[k] = FFT_RATIOS[k].inv();
}
assert(FFT_ROOTS[1] == M - 1U);
}
// as[rev(i)] <- \sum_j \zeta^(ij) as[j]
void fft(ModInt<M> *as, int n) const {
assert(!(n & (n - 1))); assert(1 <= n); assert(n <= 1 << K);
int m = n;
if (m >>= 1) {
for (int i = 0; i < m; ++i) {
const unsigned x = as[i + m].x; // < M
as[i + m].x = as[i].x + M - x; // < 2 M
as[i].x += x; // < 2 M
}
}
if (m >>= 1) {
ModInt<M> prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + m; ++i) {
const unsigned x = (prod * as[i + m]).x; // < M
as[i + m].x = as[i].x + M - x; // < 3 M
as[i].x += x; // < 3 M
}
prod *= FFT_RATIOS[__builtin_ctz(++h)];
}
}
for (; m; ) {
if (m >>= 1) {
ModInt<M> prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + m; ++i) {
const unsigned x = (prod * as[i + m]).x; // < M
as[i + m].x = as[i].x + M - x; // < 4 M
as[i].x += x; // < 4 M
}
prod *= FFT_RATIOS[__builtin_ctz(++h)];
}
}
if (m >>= 1) {
ModInt<M> prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + m; ++i) {
const unsigned x = (prod * as[i + m]).x; // < M
as[i].x = (as[i].x >= M2) ? (as[i].x - M2) : as[i].x; // < 2 M
as[i + m].x = as[i].x + M - x; // < 3 M
as[i].x += x; // < 3 M
}
prod *= FFT_RATIOS[__builtin_ctz(++h)];
}
}
}
for (int i = 0; i < n; ++i) {
as[i].x = (as[i].x >= M2) ? (as[i].x - M2) : as[i].x; // < 2 M
as[i].x = (as[i].x >= M) ? (as[i].x - M) : as[i].x; // < M
}
}
// as[i] <- (1/n) \sum_j \zeta^(-ij) as[rev(j)]
void invFft(ModInt<M> *as, int n) const {
assert(!(n & (n - 1))); assert(1 <= n); assert(n <= 1 << K);
int m = 1;
if (m < n >> 1) {
ModInt<M> prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + m; ++i) {
const unsigned long long y = as[i].x + M - as[i + m].x; // < 2 M
as[i].x += as[i + m].x; // < 2 M
as[i + m].x = (prod.x * y) % M; // < M
}
prod *= INV_FFT_RATIOS[__builtin_ctz(++h)];
}
m <<= 1;
}
for (; m < n >> 1; m <<= 1) {
ModInt<M> prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + (m >> 1); ++i) {
const unsigned long long y = as[i].x + M2 - as[i + m].x; // < 4 M
as[i].x += as[i + m].x; // < 4 M
as[i].x = (as[i].x >= M2) ? (as[i].x - M2) : as[i].x; // < 2 M
as[i + m].x = (prod.x * y) % M; // < M
}
for (int i = i0 + (m >> 1); i < i0 + m; ++i) {
const unsigned long long y = as[i].x + M - as[i + m].x; // < 2 M
as[i].x += as[i + m].x; // < 2 M
as[i + m].x = (prod.x * y) % M; // < M
}
prod *= INV_FFT_RATIOS[__builtin_ctz(++h)];
}
}
if (m < n) {
for (int i = 0; i < m; ++i) {
const unsigned y = as[i].x + M2 - as[i + m].x; // < 4 M
as[i].x += as[i + m].x; // < 4 M
as[i + m].x = y; // < 4 M
}
}
const ModInt<M> invN = ModInt<M>(n).inv();
for (int i = 0; i < n; ++i) {
as[i] *= invN;
}
}
void fft(vector<ModInt<M>> &as) const {
fft(as.data(), as.size());
}
void invFft(vector<ModInt<M>> &as) const {
invFft(as.data(), as.size());
}
vector<ModInt<M>> convolve(vector<ModInt<M>> as, vector<ModInt<M>> bs) const {
if (as.empty() || bs.empty()) return {};
const int len = as.size() + bs.size() - 1;
int n = 1;
for (; n < len; n <<= 1) {}
as.resize(n); fft(as);
bs.resize(n); fft(bs);
for (int i = 0; i < n; ++i) as[i] *= bs[i];
invFft(as);
as.resize(len);
return as;
}
vector<ModInt<M>> square(vector<ModInt<M>> as) const {
if (as.empty()) return {};
const int len = as.size() + as.size() - 1;
int n = 1;
for (; n < len; n <<= 1) {}
as.resize(n); fft(as);
for (int i = 0; i < n; ++i) as[i] *= as[i];
invFft(as);
as.resize(len);
return as;
}
};
// M0 M1 M2 = 789204840662082423367925761 (> 7.892 * 10^26, > 2^89)
// M0 M3 M4 M5 M6 = 797766583174034668024539679147517452591562753 (> 7.977 * 10^44, > 2^149)
const Fft<998244353U, 3U, 23> FFT0;
const Fft<897581057U, 3U, 23> FFT1;
const Fft<880803841U, 26U, 23> FFT2;
const Fft<985661441U, 3U, 22> FFT3;
const Fft<943718401U, 7U, 22> FFT4;
const Fft<935329793U, 3U, 22> FFT5;
const Fft<918552577U, 5U, 22> FFT6;
// T = unsigned, unsigned long long, ModInt<M>
template <class T, unsigned M0, unsigned M1, unsigned M2>
T garner(ModInt<M0> a0, ModInt<M1> a1, ModInt<M2> a2) {
static const ModInt<M1> INV_M0_M1 = ModInt<M1>(M0).inv();
static const ModInt<M2> INV_M0M1_M2 = (ModInt<M2>(M0) * M1).inv();
const ModInt<M1> b1 = INV_M0_M1 * (a1 - a0.x);
const ModInt<M2> b2 = INV_M0M1_M2 * (a2 - (ModInt<M2>(b1.x) * M0 + a0.x));
return (T(b2.x) * M1 + b1.x) * M0 + a0.x;
}
template <class T, unsigned M0, unsigned M1, unsigned M2, unsigned M3, unsigned M4>
T garner(ModInt<M0> a0, ModInt<M1> a1, ModInt<M2> a2, ModInt<M3> a3, ModInt<M4> a4) {
static const ModInt<M1> INV_M0_M1 = ModInt<M1>(M0).inv();
static const ModInt<M2> INV_M0M1_M2 = (ModInt<M2>(M0) * M1).inv();
static const ModInt<M3> INV_M0M1M2_M3 = (ModInt<M3>(M0) * M1 * M2).inv();
static const ModInt<M4> INV_M0M1M2M3_M4 = (ModInt<M4>(M0) * M1 * M2 * M3).inv();
const ModInt<M1> b1 = INV_M0_M1 * (a1 - a0.x);
const ModInt<M2> b2 = INV_M0M1_M2 * (a2 - (ModInt<M2>(b1.x) * M0 + a0.x));
const ModInt<M3> b3 = INV_M0M1M2_M3 * (a3 - ((ModInt<M3>(b2.x) * M1 + b1.x) * M0 + a0.x));
const ModInt<M4> b4 = INV_M0M1M2M3_M4 * (a4 - (((ModInt<M4>(b3.x) * M2 + b2.x) * M1 + b1.x) * M0 + a0.x));
return (((T(b4.x) * M3 + b3.x) * M2 + b2.x) * M1 + b1.x) * M0 + a0.x;
}
///////////////////////////////////////////////////////////////////////////////
vector<Mint> convolve(const vector<Mint> &as, const vector<Mint> &bs) {
static constexpr unsigned M0 = decltype(FFT0)::M;
static constexpr unsigned M1 = decltype(FFT1)::M;
static constexpr unsigned M2 = decltype(FFT2)::M;
if (as.empty() || bs.empty()) return {};
const int asLen = as.size(), bsLen = bs.size();
vector<ModInt<M0>> as0(asLen), bs0(bsLen);
for (int i = 0; i < asLen; ++i) as0[i] = as[i].x;
for (int i = 0; i < bsLen; ++i) bs0[i] = bs[i].x;
const vector<ModInt<M0>> cs0 = FFT0.convolve(as0, bs0);
vector<ModInt<M1>> as1(asLen), bs1(bsLen);
for (int i = 0; i < asLen; ++i) as1[i] = as[i].x;
for (int i = 0; i < bsLen; ++i) bs1[i] = bs[i].x;
const vector<ModInt<M1>> cs1 = FFT1.convolve(as1, bs1);
vector<ModInt<M2>> as2(asLen), bs2(bsLen);
for (int i = 0; i < asLen; ++i) as2[i] = as[i].x;
for (int i = 0; i < bsLen; ++i) bs2[i] = bs[i].x;
const vector<ModInt<M2>> cs2 = FFT2.convolve(as2, bs2);
vector<Mint> cs(asLen + bsLen - 1);
for (int i = 0; i < asLen + bsLen - 1; ++i) {
cs[i] = garner<Mint>(cs0[i], cs1[i], cs2[i]);
}
return cs;
}
vector<Mint> square(const vector<Mint> &as) {
static constexpr unsigned M0 = decltype(FFT0)::M;
static constexpr unsigned M1 = decltype(FFT1)::M;
static constexpr unsigned M2 = decltype(FFT2)::M;
if (as.empty()) return {};
const int asLen = as.size();
vector<ModInt<M0>> as0(asLen);
for (int i = 0; i < asLen; ++i) as0[i] = as[i].x;
const vector<ModInt<M0>> cs0 = FFT0.square(as0);
vector<ModInt<M1>> as1(asLen);
for (int i = 0; i < asLen; ++i) as1[i] = as[i].x;
const vector<ModInt<M1>> cs1 = FFT1.square(as1);
vector<ModInt<M2>> as2(asLen);
for (int i = 0; i < asLen; ++i) as2[i] = as[i].x;
const vector<ModInt<M2>> cs2 = FFT2.square(as2);
vector<Mint> cs(asLen + asLen - 1);
for (int i = 0; i < asLen + asLen - 1; ++i) {
cs[i] = garner<Mint>(cs0[i], cs1[i], cs2[i]);
}
return cs;
}
vector<Mint> polyInv(const vector<Mint> &as, int n) {
assert(!as.empty()); assert(as[0]);
const int asLen = as.size();
vector<Mint> bs{as[0].inv()};
for (int m = 1; m < n; m <<= 1) {
const vector<Mint> as0(as.begin(), as.begin() + min(m << 1, asLen));
const auto cs = convolve(as0, square(bs));
bs.resize(m << 1, 0);
for (int i = m; i < m << 1 && i < (int)cs.size(); ++i) bs[i] -= cs[i];
}
return bs;
}
/*
problem
count [1, M]^N s.t.
can erase by operations:
erase contiguous subseq. of length >= 2 s.t. front == back
state: #{ valid prefix's next }
f: whole is valid
g: whole is invalid
f[i + 1][j] += f[i][j] * j;
g[i + 1][j + 1] += f[i][j] * (M - j);
f[i + 1][j] += g[i][j] * j;
g[i + 1][j] += g[i][j] * (M - j);
want: f[0][0] -> f[N][*]
0*
0* (M-0) (M-1)* 1 1*
0* (M-0) (M-1)* 1 1* (M-1) (M-2)* 2 2*
...
*/
int N, M;
struct Result {
Mint o;
vector<Mint> ps, qs;
};
Result rec(int l, int r) {
Result ret;
if (l + 1 == r) {
ret.o = Mint(M - l) * Mint(1 + l);
ret.ps = ret.qs = {1, -Mint(M), Mint(M - 1 - l) * Mint(1 + l)};
} else {
const int mid = (l + r) / 2;
const auto resL = rec(l, mid);
const auto resR = rec(mid, r);
ret.o = resL.o * resR.o;
ret.ps = convolve(resL.ps, resR.qs);
for (int i = 0; i < (int)resR.ps.size(); ++i) ret.ps[2 * (mid - l) + i] += resL.o * resR.ps[i];
ret.qs = convolve(resL.qs, resR.qs);
}
// cerr<<l<<" "<<r<<": "<<ret.o<<" "<<ret.ps<<" "<<ret.qs<<endl;
return ret;
}
int main() {
for (; ~scanf("%d%d", &N, &M); ) {
const auto res = rec(0, N / 2 + 1);
auto ans = convolve(res.ps, polyInv(res.qs, N + 1));
ans.resize(N + 1);
// cerr<<ans<<endl;
printf("%u\n", ans[N].x);
}
return 0;
}
詳細信息
Subtask #1:
score: 1
Accepted
Test #1:
score: 1
Accepted
time: 0ms
memory: 3868kb
input:
4 2
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 0ms
memory: 4140kb
input:
1 1
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 4140kb
input:
1 3
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
1 5
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
2 2
output:
2
result:
ok single line: '2'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
2 4
output:
4
result:
ok single line: '4'
Test #7:
score: 0
Accepted
time: 0ms
memory: 4136kb
input:
3 1
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
3 3
output:
9
result:
ok single line: '9'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3892kb
input:
3 5
output:
25
result:
ok single line: '25'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3876kb
input:
4 2
output:
10
result:
ok single line: '10'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
4 4
output:
76
result:
ok single line: '76'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
5 1
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
5 3
output:
117
result:
ok single line: '117'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3852kb
input:
5 5
output:
825
result:
ok single line: '825'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
7 2
output:
116
result:
ok single line: '116'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
9 2
output:
496
result:
ok single line: '496'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3944kb
input:
11 2
output:
2028
result:
ok single line: '2028'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
13 2
output:
8168
result:
ok single line: '8168'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3940kb
input:
10 3
output:
48237
result:
ok single line: '48237'
Subtask #2:
score: 1
Accepted
Test #20:
score: 1
Accepted
time: 0ms
memory: 3940kb
input:
1 2
output:
0
result:
ok single line: '0'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
1 4
output:
0
result:
ok single line: '0'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
2 1
output:
1
result:
ok single line: '1'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
2 3
output:
3
result:
ok single line: '3'
Test #24:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
2 5
output:
5
result:
ok single line: '5'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3896kb
input:
3 2
output:
4
result:
ok single line: '4'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
3 4
output:
16
result:
ok single line: '16'
Test #27:
score: 0
Accepted
time: 0ms
memory: 3880kb
input:
4 1
output:
1
result:
ok single line: '1'
Test #28:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
4 3
output:
33
result:
ok single line: '33'
Test #29:
score: 0
Accepted
time: 0ms
memory: 4140kb
input:
4 5
output:
145
result:
ok single line: '145'
Test #30:
score: 0
Accepted
time: 0ms
memory: 3944kb
input:
5 2
output:
24
result:
ok single line: '24'
Test #31:
score: 0
Accepted
time: 0ms
memory: 4140kb
input:
5 4
output:
352
result:
ok single line: '352'
Test #32:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
6 2
output:
54
result:
ok single line: '54'
Test #33:
score: 0
Accepted
time: 0ms
memory: 4144kb
input:
8 2
output:
242
result:
ok single line: '242'
Test #34:
score: 0
Accepted
time: 0ms
memory: 4140kb
input:
10 2
output:
1006
result:
ok single line: '1006'
Test #35:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
12 2
output:
4074
result:
ok single line: '4074'
Test #36:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
14 2
output:
16358
result:
ok single line: '16358'
Subtask #3:
score: 1
Accepted
Test #37:
score: 1
Accepted
time: 3ms
memory: 4296kb
input:
1689 2
output:
998472085
result:
ok single line: '998472085'
Test #38:
score: 0
Accepted
time: 13ms
memory: 4084kb
input:
2748 2
output:
451726470
result:
ok single line: '451726470'
Test #39:
score: 0
Accepted
time: 6ms
memory: 4036kb
input:
1204 2
output:
449822862
result:
ok single line: '449822862'
Test #40:
score: 0
Accepted
time: 13ms
memory: 4060kb
input:
2727 2
output:
203224669
result:
ok single line: '203224669'
Test #41:
score: 0
Accepted
time: 4ms
memory: 3984kb
input:
984 2
output:
175698237
result:
ok single line: '175698237'
Test #42:
score: 0
Accepted
time: 14ms
memory: 4404kb
input:
3000 2
output:
165694478
result:
ok single line: '165694478'
Subtask #4:
score: 1
Accepted
Test #43:
score: 1
Accepted
time: 1ms
memory: 4132kb
input:
97 83
output:
613159502
result:
ok single line: '613159502'
Test #44:
score: 0
Accepted
time: 1ms
memory: 3884kb
input:
109 112
output:
749531455
result:
ok single line: '749531455'
Test #45:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
92 84
output:
754509307
result:
ok single line: '754509307'
Test #46:
score: 0
Accepted
time: 1ms
memory: 3888kb
input:
111 116
output:
434377961
result:
ok single line: '434377961'
Test #47:
score: 0
Accepted
time: 1ms
memory: 4160kb
input:
95 82
output:
345936119
result:
ok single line: '345936119'
Test #48:
score: 0
Accepted
time: 1ms
memory: 3848kb
input:
106 94
output:
551192069
result:
ok single line: '551192069'
Test #49:
score: 0
Accepted
time: 1ms
memory: 3880kb
input:
110 94
output:
41938476
result:
ok single line: '41938476'
Subtask #5:
score: 1
Accepted
Test #50:
score: 1
Accepted
time: 6ms
memory: 4292kb
input:
1168 346407973
output:
112579949
result:
ok single line: '112579949'
Test #51:
score: 0
Accepted
time: 0ms
memory: 3960kb
input:
313 68910142
output:
83916341
result:
ok single line: '83916341'
Test #52:
score: 0
Accepted
time: 0ms
memory: 4180kb
input:
161 64396010
output:
499230829
result:
ok single line: '499230829'
Test #53:
score: 0
Accepted
time: 3ms
memory: 4308kb
input:
1836 434479347
output:
873178296
result:
ok single line: '873178296'
Test #54:
score: 0
Accepted
time: 7ms
memory: 4008kb
input:
1588 392
output:
611721416
result:
ok single line: '611721416'
Subtask #6:
score: 1
Accepted
Test #55:
score: 1
Accepted
time: 1ms
memory: 4140kb
input:
123 468402382
output:
827499041
result:
ok single line: '827499041'
Test #56:
score: 0
Accepted
time: 4ms
memory: 3972kb
input:
1016 982915840
output:
813922878
result:
ok single line: '813922878'
Test #57:
score: 0
Accepted
time: 0ms
memory: 3980kb
input:
709 58889328
output:
215179237
result:
ok single line: '215179237'
Test #58:
score: 0
Accepted
time: 3ms
memory: 3996kb
input:
884 504516691
output:
199072709
result:
ok single line: '199072709'
Test #59:
score: 0
Accepted
time: 6ms
memory: 4288kb
input:
1414 131
output:
292793609
result:
ok single line: '292793609'
Subtask #7:
score: 1
Accepted
Test #60:
score: 1
Accepted
time: 3ms
memory: 3976kb
input:
779 140176290
output:
438118426
result:
ok single line: '438118426'
Test #61:
score: 0
Accepted
time: 2ms
memory: 3936kb
input:
488 292223807
output:
720591335
result:
ok single line: '720591335'
Test #62:
score: 0
Accepted
time: 3ms
memory: 3956kb
input:
849 198249514
output:
936832149
result:
ok single line: '936832149'
Test #63:
score: 0
Accepted
time: 4ms
memory: 3956kb
input:
929 316667619
output:
684900471
result:
ok single line: '684900471'
Test #64:
score: 0
Accepted
time: 6ms
memory: 4032kb
input:
1282 216
output:
39918106
result:
ok single line: '39918106'
Subtask #8:
score: 1
Accepted
Test #65:
score: 1
Accepted
time: 9ms
memory: 4048kb
input:
2315 21373850
output:
692830582
result:
ok single line: '692830582'
Test #66:
score: 0
Accepted
time: 13ms
memory: 4316kb
input:
2819 54930015
output:
704850526
result:
ok single line: '704850526'
Test #67:
score: 0
Accepted
time: 13ms
memory: 4116kb
input:
2876 518453378
output:
160061956
result:
ok single line: '160061956'
Test #68:
score: 0
Accepted
time: 13ms
memory: 4220kb
input:
2722 126086649
output:
930849830
result:
ok single line: '930849830'
Test #69:
score: 0
Accepted
time: 13ms
memory: 4228kb
input:
2508 121810583
output:
5167845
result:
ok single line: '5167845'
Test #70:
score: 0
Accepted
time: 13ms
memory: 4120kb
input:
2500 4000
output:
805467400
result:
ok single line: '805467400'
Subtask #9:
score: 1
Accepted
Test #71:
score: 1
Accepted
time: 13ms
memory: 4108kb
input:
2631 684393357
output:
936211679
result:
ok single line: '936211679'
Test #72:
score: 0
Accepted
time: 13ms
memory: 4036kb
input:
2913 516585428
output:
664802101
result:
ok single line: '664802101'
Test #73:
score: 0
Accepted
time: 14ms
memory: 4296kb
input:
2966 566883908
output:
74800796
result:
ok single line: '74800796'
Test #74:
score: 0
Accepted
time: 13ms
memory: 4196kb
input:
2508 135568838
output:
345174594
result:
ok single line: '345174594'
Test #75:
score: 0
Accepted
time: 10ms
memory: 4012kb
input:
2948 557406795
output:
163500664
result:
ok single line: '163500664'
Test #76:
score: 0
Accepted
time: 13ms
memory: 4188kb
input:
2500 1000
output:
996821828
result:
ok single line: '996821828'
Subtask #10:
score: 1
Accepted
Test #77:
score: 1
Accepted
time: 14ms
memory: 4168kb
input:
3000 1000000000
output:
543073891
result:
ok single line: '543073891'
Test #78:
score: 0
Accepted
time: 10ms
memory: 4432kb
input:
3000 999999999
output:
453659722
result:
ok single line: '453659722'
Test #79:
score: 0
Accepted
time: 14ms
memory: 4160kb
input:
3000 999999998
output:
98366752
result:
ok single line: '98366752'
Test #80:
score: 0
Accepted
time: 14ms
memory: 4428kb
input:
2999 1000000000
output:
282559837
result:
ok single line: '282559837'
Test #81:
score: 0
Accepted
time: 14ms
memory: 4104kb
input:
2999 999999999
output:
720365773
result:
ok single line: '720365773'
Test #82:
score: 0
Accepted
time: 14ms
memory: 4132kb
input:
2999 999999998
output:
461705162
result:
ok single line: '461705162'
Test #83:
score: 0
Accepted
time: 14ms
memory: 4148kb
input:
2998 1000000000
output:
842668451
result:
ok single line: '842668451'
Test #84:
score: 0
Accepted
time: 14ms
memory: 4152kb
input:
2998 999999999
output:
304660083
result:
ok single line: '304660083'
Test #85:
score: 0
Accepted
time: 14ms
memory: 4160kb
input:
2998 999999998
output:
92840037
result:
ok single line: '92840037'
Test #86:
score: 0
Accepted
time: 14ms
memory: 4428kb
input:
3000 1
output:
1
result:
ok single line: '1'
Test #87:
score: 0
Accepted
time: 14ms
memory: 4112kb
input:
3000 100
output:
513574771
result:
ok single line: '513574771'