QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#371484#618. 多项式乘法Isrothy100 ✓425ms35864kbC++2320.1kb2024-03-30 13:13:472024-03-30 13:13:49

Judging History

你现在查看的是最新测评结果

  • [2024-03-30 13:13:49]
  • 评测
  • 测评结果:100
  • 用时:425ms
  • 内存:35864kb
  • [2024-03-30 13:13:47]
  • 提交

answer

#include <bit>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <span>
#include <unordered_map>
#include <vector>


constexpr int mod = 998244353;
constexpr int g = 3;

int32_t constexpr mul_mod(int32_t a, int32_t b, int32_t mod) {
    return static_cast<int>(static_cast<int64_t>(a) * b % mod);
}
int64_t constexpr mul_mod(int64_t a, int64_t b, int64_t mod) {
#ifdef __SIZEOF_INT128__
    return static_cast<int64_t>(static_cast<__int128>(a) * b % mod);
#else
    int64_t res = 0;
    for (b = (b % mod + mod) % mod; b; b >>= 1) {
        if (b & 1) {
            res = (res + a) % mod;
        }
        a = (a + a) % mod;
    }
    return res;
#endif
}
template<typename T>
constexpr std::tuple<T, T, T> ex_gcd(const T &a, const T &b) {
    if (b == 0) {
        return {a, T(1), T(0)};
    }
    auto [d, x, y] = ex_gcd(b, a % b);
    return {d, y, x - a / b * y};
}
template<typename T, typename U>
constexpr T power(T x, U k, const std::function<T(T, T)> &multiply) {
    T res{1};
    for (; k; k >>= 1) {
        if (k & 1) {
            res = multiply(res, x);
        }
        x = multiply(x, x);
    }
    return res;
}
template<typename T, typename U>
constexpr T power(T x, U k, const T &mod) {
    T res{1};
    for (; k; k >>= 1) {
        if (k & 1) {
            res = mul_mod(res, x, mod);
        }
        x = mul_mod(x, x, mod);
    }
    return res;
}
template<typename T>
constexpr T inverse(const T &a, const T &mod) {
    auto [d, x, y] = ex_gcd(a, mod);
    return d * x;
}
template<typename T>
std::optional<T> bsgs(const T &a, T b, const T &mod) {
    if (mod == 1) {
        return 0;
    }
    T w{1}, x{1}, s{static_cast<T>(std::sqrt(mod)) + 1};
    std::unordered_map<T, T> map;
    map.reserve(s);
    for (T k = 1; k <= s; ++k) {
        b = mul_mod(b, a, mod);
        w = mul_mod(w, a, mod);
        map[b] = k;
    }
    for (T k = 1; k <= s; ++k) {
        x = mul_mod(x, w, mod);
        if (map.contains(x)) {
            return (k * s - map[x]) % (mod - 1);
        }
    }
    return std::nullopt;
}
template<typename T>
std::optional<T> ex_bsgs(T a, T b, const T &mod) {
    a = (a % mod + mod) % mod;
    b = (b % mod + mod) % mod;
    if (b == 1 || mod == 1) {
        return 0;
    }
    auto d = gcd(a, mod);
    if (b % d) {
        return std::nullopt;
    }
    if (d == 1) {
        return bsgs(a, b, mod);
    }
    auto g = inverse(a / d, mod / d);
    auto x = ex_bsgs(a, b / d * g, mod / d);
    if (!x.has_value()) {
        return std::nullopt;
    }
    return x.value() + 1;
}
template<typename T>
struct Crt {
    std::vector<T> mt;
    T m{};
    Crt() = default;
    explicit Crt(std::span<T> a) : mt(a.size()) {
        m = std::accumulate(a.begin(), a.end(), T{1}, std::multiplies<>());
        for (int i = 0; i < a.size(); ++i) {
            auto mi = m / a[i];
            mt[i] = mi * inverse(mi, a[i]) % m;
        }
    }
    T query(std::span<T> b) {
        assert(b.size() == mt.size());
        T res = 0;
        for (int i = 0; i < mt.size(); ++i) {
            res = (res + b[i] * mt[i]) % m;
        }
        return res;
    }
};
template<typename T>
auto ex_crt(T a1, T m1, T a2, T m2) -> std::optional<std::pair<T, T>> {
    auto [d, x, y] = ex_gcd(m1, m2);
    if ((a2 - a1) % d) {
        return std::nullopt;
    }
    auto m = m1 / d * m2;
    auto t = ((a2 - a1) / d * x % (m2 / d)) * m1 % m;
    auto a = (a1 + t) % m;
    if (a < 0) {
        a += m;
    }
    return std::pair{a, m};
}
auto sieve_of_euler(std::span<bool> is_composite) {
    auto n = is_composite.size();
    std::vector<int> primes;
    primes.reserve(static_cast<int>(static_cast<double>(n) / std::log(n)));
    primes.push_back(0);
    for (int i = 2; i < n; ++i) {
        if (!is_composite[i]) {
            primes.push_back(i);
        }
        for (int j = 1; j < primes.size() && i * primes[j] < n; ++j) {
            is_composite[i * primes[j]] = true;
            if (i % primes[j] == 0) {
                break;
            }
        }
    }
    return primes;
}
template<typename T>
std::optional<T> primitive_root(T n, std::span<int> primes) {
    if (n == 2 || n == 4) {
        return n - 1;
    }
    if (n == 1 || (n & 3) == 0) {
        return std::nullopt;
    }
    auto a = prime_factors(n, primes);
    if (2 < a.size() || (a.size() == 2 && a[0] != 2)) {
        return std::nullopt;
    }
    T m = a.size() == 2 ? n / 2 / a[1] * (a[1] - 1) : n / a[0] * (a[0] - 1);
    auto b = prime_factors(m, primes);
    for (T g{2}; g < n; ++g) {
        if (power(g, m, n) == 1
            && std::all_of(b.begin(), b.end(), [&](auto p) { return power(g, m / p, n) != 1; })) {
            return g;
        }
    }
    return std::nullopt;
}
template<typename T>
bool is_prime(const T &n) {
    if (n < 2) {
        return false;
    }
    if (~n & 1) {
        return n == 2;
    }
    auto d = n - 1, s = 0;
    for (; ~d & 1; d >>= 1) {
        ++s;
    }
    static constexpr auto p = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37};
    return std::none_of(p.begin(), p.end(), [=](auto a) {
        if (a == n) {
            return false;
        }
        T x = power<T, T>(a, d, n);
        if (x == 1 || x == n - 1) {
            return false;
        }
        for (int i = 1; i < s; ++i) {
            x = mul_mod(x, x, n);
            if (x == n - 1) {
                return false;
            }
        }
        return true;
    });
}
template<typename T>
T pollard_rho(const T &n) {
    if (is_prime(n)) {
        return n;
    }
    for (auto p: {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}) {
        if (n % p == 0) {
            return p;
        }
    }
    std::uniform_int_distribution<T> dist(1, n - 1);
    while (true) {
        static std::mt19937 mt_rand(std::random_device{}());
        auto c = dist(mt_rand);
        auto f = [&](const T &x) {
            return (mul_mod(x, x, n) + c) % n;
        };
        auto t = f(0), r = f(t);
        int steps = 1;
        while (t != r) {
            T prod{1};
            for (int i = 0; i < steps; ++i) {
                if (auto tmp = mul_mod(prod, std::abs(t - r), n)) {
                    prod = tmp;
                    t = f(t);
                    r = f(f(r));
                } else {
                    break;
                }
            }
            if (auto d = std::gcd(prod, n); d != 1) {
                return d;
            }
            steps = std::min(128, steps << 1);
        }
    }
}
template<typename T>
auto prime_factors(const T &n) {
    std::queue<T> q;
    std::vector<T> res;
    for (q.push(n); !q.empty(); q.pop()) {
        if (auto x = q.front(); is_prime(x)) {
            res.push_back(x);
        } else {
            auto d = pollard_rho(x);
            q.push(d);
            q.push(x / d);
        }
    }
    std::sort(res.begin(), res.end());
    res.erase(std::unique(res.begin(), res.end()), res.end());
    return res;
}
namespace polynomial {
    auto congruence_equation(int64_t a, int64_t b, int64_t p) {
        b = (b % p + p) % p;
        auto d = std::gcd(a, p);
        std::tie(a, b, p) = std::make_tuple(a / d, b / d, p / d);
        return (b * inverse(a, p) % p + p) % p;
    }
    int64_t quadratic_residue(int64_t x, int64_t mod, int64_t g) {
        if (!x) {
            return 0;
        }
        x = bsgs(g, x, mod).value();
        x = power(g, congruence_equation(2, x, mod - 1), mod);
        return std::min((int64_t) x, (int64_t) (mod - x));
    }
    template<int Mod, int G>
    struct polynomial : private std::vector<int> {
        using std::vector<int>::vector;
        using std::vector<int>::operator[];
        using std::vector<int>::begin;
        using std::vector<int>::end;
        using std::vector<int>::size;
        using std::vector<int>::resize;
        auto &operator*=(int64_t k) {
            for (auto &x: *this) {
                x = x * k % Mod;
            }
            return *this;
        }
        auto &operator+=(const polynomial<Mod, G> &rhs) {
            if (rhs.size() > size()) {
                resize(rhs.size());
            }
            for (int i = 0; i < rhs.size(); ++i) {
                (*this)[i] = ((*this)[i] + rhs[i]) % Mod;
            }
            return *this;
        }
        auto &operator-=(const polynomial<Mod, G> &rhs) {
            if (rhs.size() > size()) {
                resize(rhs.size());
            }
            for (int i = 0; i < rhs.size(); ++i) {
                (*this)[i] = ((*this)[i] - rhs[i]) % Mod;
            }
            return *this;
        }
        auto &operator+=(int64_t x) {
            (*this)[0] = ((*this)[0] + x) % Mod;
            return *this;
        }
        auto &operator-=(int64_t x) {
            (*this)[0] = ((*this)[0] - x) % Mod;
            return *this;
        }
        auto &operator*=(polynomial<Mod, G> rhs) {
            auto m = size() + rhs.size() - 1;
            auto n = std::bit_ceil(m);
            *this = dft(modXN(std::move(*this), n), 1);
            rhs = dft(modXN(std::move(rhs), n), 1);
            for (int i = 0; i < n; ++i) {
                (*this)[i] = (int64_t) (*this)[i] * rhs[i] % Mod;
            }
            *this = modXN(dft(std::move(*this), -1), m);
            return *this;
        }
    };
    template<int Mod, int G>
    auto dft(polynomial<Mod, G> a, int f) {
        static constexpr auto wn{[]() constexpr {
            constexpr auto len = std::countr_zero(static_cast<uint64_t>(Mod) - 1);
            std::array<std::array<int, len>, 2> wn{};
            for (int i = 0; i < len; ++i) {
                wn[0][i] = power(G, (Mod - 1) >> (i + 1), Mod);
                wn[1][i] = inverse(wn[0][i], Mod);
            }
            return wn;
        }()};
        int n = a.size();
        std::vector<int> w(n);
        for (int i = 0, j = 0; i < n; ++i) {
            if (i < j) {
                std::swap(a[i], a[j]);
            }
            for (int l = n >> 1; (j ^= l) < l; l >>= 1)
                ;
        }
        w[0] = 1;
        for (int i = 0; 1 << i < n; ++i) {
            for (int j = (1 << (i + 1)) - 1; j; --j) {
                w[j] = j & 1 ? (int64_t) w[j >> 1] * wn[(1 - f) / 2][i] % Mod : w[j >> 1];
            }
            for (int j = 0; j < n; j += 1 << (i + 1)) {
                auto *p = &a[j], *q = &a[j | 1 << i], *r = &w[0];
                for (int k = 0; k < 1 << i; ++k) {
                    auto t = (int64_t) q[k] * r[k];
                    q[k] = (p[k] - t) % Mod;
                    p[k] = (p[k] + t) % Mod;
                }
            }
        }
        if (f == -1) {
            int64_t in = ::inverse(n, Mod);
            for (auto &x: a) {
                x = x * in % Mod;
            }
        }
        return a;
    }
    template<int Mod, int G>
    auto modXN(polynomial<Mod, G> &&p, int n) {
        p.resize(n);
        return p;
    }
    template<int Mod, int G>
    auto modXN(const polynomial<Mod, G> &p, int n) {
        polynomial<Mod, G> res(n);
        std::copy(p.begin(), p.begin() + std::min(n, p.size()), res.begin());
        return res;
    }
    template<int Mod, int G>
    auto divXN(polynomial<Mod, G> &&p, int n) {
        std::copy(p.begin() + n, p.end(), p.begin());
        p.resize(p.size() - n);
        return p;
    }
    template<int Mod, int G>
    auto divXN(const polynomial<Mod, G> &p, int n) {
        polynomial res(p.size() - n);
        std::copy(p.begin() + n, p.end(), res.begin());
        return res;
    }
    template<int Mod, int G>
    auto reverse(polynomial<Mod, G> p) {
        std::reverse(p.begin(), p.end());
        return p;
    }
    template<int Mod, int G>
    auto operator+(polynomial<Mod, G> lhs, const polynomial<Mod, G> &rhs) {
        return lhs += rhs;
    }
    template<int Mod, int G>
    auto operator-(polynomial<Mod, G> lhs, const polynomial<Mod, G> &rhs) {
        return lhs -= rhs;
    }
    template<int Mod, int G>
    auto operator+(int64_t x, polynomial<Mod, G> p) {
        return p += x;
    }
    template<int Mod, int G>
    auto operator+(polynomial<Mod, G> p, int64_t x) {
        return p += x;
    }
    template<int Mod, int G>
    auto operator-(polynomial<Mod, G> p, int64_t x) {
        return p -= x;
    }
    template<int Mod, int G>
    auto operator-(int64_t x, polynomial<Mod, G> p) {
        return p -= x;
    }
    template<int Mod, int G>
    auto operator*(int64_t x, polynomial<Mod, G> p) {
        return p *= x;
    }
    template<int Mod, int G>
    auto operator*(polynomial<Mod, G> p, int64_t x) {
        return p *= x;
    }
    template<int Mod, int G>
    auto operator*(polynomial<Mod, G> lhs, const polynomial<Mod, G> &rhs) {
        return lhs *= rhs;
    }
    template<int Mod, int G>
    auto inverse(const polynomial<Mod, G> &p) {
        polynomial<Mod, G> res = {static_cast<int>(inv(p[0], Mod))};
        auto n = std::bit_ceil(p.size());
        for (int i = 2; i <= n; i <<= 1) {
            auto a = dft(modXN(modXN(p, i), i << 1), 1);
            auto b = dft(modXN(std::move(res), i << 1), 1);
            for (int j = 0; j < i << 1; ++j) {
                b[j] = b[j] * (2 - (int64_t) a[j] * b[j] % Mod) % Mod;
            }
            res = modXN(dft(std::move(b), -1), i);
        }
        return modXN(std::move(res), p.size());
    }
    template<int Mod, int G>
    auto derivative(polynomial<Mod, G> p) {
        for (int i = 1; i < p.size(); ++i) {
            p[i - 1] = (int64_t) i * p[i] % Mod;
        }
        p.resize(p.size() - 1);
        return p;
    }
    template<int Mod, int G>
    auto integral(polynomial<Mod, G> p) {
        p.resize(p.size() + 1);
        for (int i = (int) p.size() - 1; i >= 0; --i) {
            p[i] = ::inverse(i, Mod) * p[i - 1] % Mod;
        }
        p[0] = 0;
        return p;
    }
    template<int Mod, int G>
    auto log(const polynomial<Mod, G> &p) {
        return modXN(integral(derivative(p) * inverse(p)), p.size());
    }
    template<int Mod, int G>
    auto exp(const polynomial<Mod, G> &p) {
        polynomial<Mod, G> res = {1};
        auto n = std::bit_ceil(p.size());
        for (int i = 2; i <= n; i <<= 1) {
            auto a = dft(modXN(modXN(p, i), i << 1), 1);
            auto b = dft(modXN(res, i << 1), 1);
            auto c = dft(modXN(log(modXN(std::move(res), i)), i << 1), 1);
            for (int j = 0; j < i << 1; ++j) {
                b[j] = (int64_t) b[j] * (1 + a[j] - c[j]) % Mod;
            }
            res = modXN(dft(std::move(b), -1), i);
        }
        return modXN(std::move(res), p.size());
    }
    template<int Mod, int G>
    auto pow(const polynomial<Mod, G> &p, int64_t k) {
        return exp(log(p) * k);
    }
    template<int Mod, int G>
    auto sqrt(const polynomial<Mod, G> &p) {
        polynomial<Mod, G> res = {static_cast<int>(quadratic_residue(p[0], Mod, G))};
        constexpr auto inv2 = ::inverse(2, Mod);
        auto n = std::bit_ceil(p.size());
        for (int i = 2; i <= n; i <<= 1) {
            auto a = dft(modXN(modXN(p, i), i << 1), 1);
            auto b = dft(modXN(res, i << 1), 1);
            auto c = dft(modXN(inverse(modXN(std::move(res), i)), i << 1), 1);
            for (int j = 0; j < i << 1; ++j) {
                b[j] = (b[j] + (int64_t) a[j] * c[j]) % Mod * inv2 % Mod;
            }
            res = modXN(dft(std::move(b), -1), i);
        }
        return modXN(std::move(res), p.size());
    }
    template<int Mod, int G>
    auto operator/(const polynomial<Mod, G> &lhs, const polynomial<Mod, G> &rhs) {
        auto n = lhs.size();
        auto m = rhs.size();
        if (n < m) {
            return polynomial<Mod, G>{0};
        }
        auto a = modXN(reverse(lhs), n - m + 1);
        auto b = modXN(reverse(rhs), n - m + 1);
        return reverse(modXN(a * inverse(b), n - m + 1));
    }
    template<int Mod, int G>
    auto operator%(const polynomial<Mod, G> &lhs, const polynomial<Mod, G> &rhs) {
        return modXN(lhs - lhs / rhs * rhs, rhs.size() - 1);
    }
    template<int Mod, int G>
    auto operator/=(polynomial<Mod, G> &lhs, const polynomial<Mod, G> &rhs) {
        return lhs = lhs / rhs;
    }
    template<int Mod, int G>
    auto operator%=(polynomial<Mod, G> &lhs, const polynomial<Mod, G> &rhs) {
        return lhs = lhs % rhs;
    }
    template<int Mod, int G>
    auto
    eva_build(int p, int l, int r, const std::vector<int> &x, std::vector<polynomial<Mod, G>> &a) {
        if (l == r) {
            a[p] = {1, l < x.size() ? -x[l] : 0};
            return;
        }
        auto mid = (l + r) >> 1;
        eva_build(p << 1, l, mid, x, a);
        eva_build(p << 1 | 1, mid + 1, r, x, a);
        a[p] = a[p << 1] * a[p << 1 | 1];
    }
    template<int Mod, int G>
    auto eva_work(
        int p,
        int l,
        int r,
        const polynomial<Mod, G> &f,
        std::vector<polynomial<Mod, G>> &a,
        std::vector<int> &res
    ) {
        if (l == r) {
            if (l < res.size()) {
                res[l] = f[0];
            }
            return;
        }
        int mid = (l + r) >> 1;
        auto fsize = f.size();
        auto n = std::bit_ceil(fsize);
        auto x = dft(modXN(f, n), 1);
        auto helper = [n, fsize](polynomial<Mod, G> x, const polynomial<Mod, G> &g) {
            auto b = dft(modXN(g, n), 1);
            for (int i = 0; i < n; ++i) {
                x[i] = (int64_t) x[i] * b[i] % Mod;
            }
            return divXN(modXN(dft(std::move(x), -1), fsize), g.size() - 1);
        };
        auto lf = helper(x, a[p << 1 | 1]);
        auto rf = helper(x, a[p << 1]);
        eva_work(p << 1, l, mid, lf, a, res);
        eva_work(p << 1 | 1, mid + 1, r, rf, a, res);
    }
    template<int Mod, int G>
    auto evaluation(const polynomial<Mod, G> &p, const std::vector<int> &x) {
        int m = std::max(x.size(), p.size() - 1);
        std::vector<polynomial<Mod, G>> a(m << 2);
        std::vector<int> res(x.size());
        eva_build(1, 0, m - 1, x, a);
        auto f = modXN(reverse(modXN(p, m + 1)) * inverse(a[1]), m + 1);
        eva_work(1, 0, m - 1, f, a, res);
        for (int i = 0; i < x.size(); ++i) {
            res[i] = (p[0] + (int64_t) res[i] * x[i]) % Mod;
        }
        return res;
    }
    template<int Mod, int G>
    polynomial<Mod, G> interpolation_work(
        int p,
        int l,
        int r,
        const std::vector<int> &y,
        std::vector<polynomial<Mod, G>> &a,
        const std::vector<int> &b
    ) {
        if (l == r) {
            return {(int) (y[l] * ::inverse<int64_t>(b[l], Mod) % Mod)};
        }
        auto mid = (l + r) >> 1;
        auto lf = interpolation_work(p << 1, l, mid, y, a, b);
        auto rf = interpolation_work(p << 1 | 1, mid + 1, r, y, a, b);
        return lf * reverse(a[p << 1 | 1]) + rf * reverse(a[p << 1]);
    }
    template<int Mod, int G>
    auto interpolation(const std::vector<int> &x, const std::vector<int> &y) {
        auto n = x.size();
        std::vector<polynomial<Mod, G>> a(n << 2);
        std::vector<int> b(n);
        eva_build(1, 0, n - 1, x, a);
        auto f = derivative(reverse(a[1]));
        auto g = modXN(reverse(modXN(f, n + 1)) * inverse(a[1]), n + 1);
        eva_work(1, 0, n - 1, g, a, b);
        for (int i = 0; i < n; ++i) {
            b[i] = (f[0] + (int64_t) b[i] * x[i]) % Mod;
        }
        return interpolation_work(1, 0, n - 1, y, a, b);
    }
}// namespace polynomial

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    polynomial::polynomial<mod, g> a(n + 1), b(m + 1);
    for (int i = 0; i <= n; ++i) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i <= m; ++i) {
        scanf("%d", &b[i]);
    }
    auto c = a * b;
    for (auto x: c) {
        printf("%d ", (x + mod) % mod);
    }
    puts("");
    return 0;
}

詳細信息

Test #1:

score: 20
Accepted
time: 1ms
memory: 3868kb

input:

96 96
600395131 184265451 942971382 534262851 830366882 542271170 294355449 501371170 797809599 964826049 276651245 375755165 662619442 941920605 328216963 507795473 460271147 874920847 818231910 156789488 590591583 732194508 793983630 93566697 836155866 305319153 432040686 621119061 835023373 57138...

output:

683858396 5532883 499734624 910262414 221004044 924081841 392466229 64190174 260661815 939986106 283456690 260629512 990528995 704246427 991946815 236857583 903415172 900324859 938555797 225258152 874945420 516870315 74759441 769850097 353889928 300397164 63689540 115003940 872945378 407694641 91843...

result:

ok 193 numbers

Test #2:

score: 20
Accepted
time: 3ms
memory: 4200kb

input:

4992 4994
471194390 313639917 705341086 119536186 430124603 244978845 185588341 13731324 707132801 88167972 927324568 846658454 523684029 5133605 767200778 502476309 539772401 778154025 266136872 183516351 260704325 49303370 475056182 928574546 740424153 277920667 708439854 746983628 839491869 53579...

output:

700935456 677302967 772159864 479386810 109686665 263919131 29567167 960045078 636326916 585682137 409426717 14510019 441964472 92801447 551536199 216995135 59736203 790078879 55883568 796138076 265361608 66124731 150347029 93682849 205256362 672081205 86396898 573029352 541084997 293480941 90518071...

result:

ok 9987 numbers

Test #3:

score: 20
Accepted
time: 6ms
memory: 4448kb

input:

29995 29992
417238081 53580806 733071257 224121793 786137422 127072245 129083351 988357079 246853229 150935424 596994106 975796660 838029970 619117898 328485797 948485083 574261409 79312345 596346086 489787404 929520168 515647000 211731260 50868568 811515357 428215135 498099163 644485329 802849075 3...

output:

115270920 49832720 758693293 745763567 322999821 510579248 697424729 850661201 678364508 817667211 668544763 136619207 562899653 692811546 351397117 768369036 573254435 891143982 717302438 707939747 41743610 540709722 240732780 931265491 38731999 642520590 630812534 632188732 342954490 225414102 836...

result:

ok 59988 numbers

Test #4:

score: 20
Accepted
time: 43ms
memory: 6952kb

input:

100000 99993
812398607 947396010 797321381 883949986 56052416 586258761 193247973 611124334 773505112 142179482 565466227 140875825 79890768 893500101 553768089 648879319 480419657 915530184 799329430 494818755 793895824 851865180 459534006 259473419 610037701 472768430 868914058 887444584 588850309...

output:

821875273 646409297 701893040 744951544 891720486 338002304 134405948 686576985 653633849 704180950 763960458 160339533 773107048 630019221 467173934 675237413 824356289 394352126 870024535 473719536 246319541 372709664 656104889 677100818 890131281 374587639 160832628 144239351 450760970 646488586 ...

result:

ok 199994 numbers

Test #5:

score: 20
Accepted
time: 425ms
memory: 35864kb

input:

999993 999994
388529697 811245378 165909114 295553883 667981275 78502012 400874009 139394758 249494489 4636487 997712665 259780805 431039016 716944209 709300152 356513646 823185021 699568300 650937921 859190797 899514799 785648601 933470757 627225124 349752104 471458923 456404256 48134357 315599086 ...

output:

199012842 735467570 660520906 870291510 102406003 509914017 591503608 692425397 149848591 232605296 411728228 285507919 90090498 682749099 507720817 425946949 937188332 619041823 738654334 153862895 272311969 793838225 260785140 350903642 151151058 631242104 304026658 123734332 23714740 438936743 77...

result:

ok 1999988 numbers