QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#541409 | #8932. Bingo | ucup-team1264# | AC ✓ | 1288ms | 11292kb | C++20 | 30.9kb | 2024-08-31 19:19:18 | 2024-08-31 19:19:20 |
Judging History
answer
// https://www.youtube.com/watch?v=R0P_f0gXXqs
// I could feel your heartbeat
// I could feel somewhere you’re looking down
// ‘Cause it’s you who I’m loving
// And it’s you that I want in need
#ifndef ONLINE_JUDGE
#include "templates/debug.hpp"
#else
#define debug(...)
#endif
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
namespace BigInteger {
// BEGIN_NOLINT
class ZeroDivisionError : public std::exception {
public:
const char *what() const throw() { return "BigInteger::divmod"; }
};
class FFTLimitExceededError : public std::exception {
public:
const char *what() const throw() { return "BigInteger::fft_mul"; }
};
class BigInteger {
protected:
using digit_t = long long;
static constexpr int WIDTH = 8;
static constexpr digit_t BASE = 1e8;
static constexpr long long FFT_LIMIT = 512;
static constexpr long long NEWTON_LIMIT = 512;
static constexpr long long NEWTON_MIN_LEVEL = 16;
digit_t *digits;
int capacity, size;
bool flag;
inline void push(const digit_t &);
inline void pop();
inline int compare(const BigInteger &) const;
static inline BigInteger fft_mul(const BigInteger &, const BigInteger &);
inline BigInteger move_l(int) const;
inline BigInteger move_r(int) const;
BigInteger newton_inv(int) const;
inline std::pair<BigInteger, BigInteger>
newton_div(const BigInteger &) const;
template <class F>
inline static BigInteger binary_op_helper(const BigInteger &,
const BigInteger &, const F &);
public:
inline void reserve(const int &);
protected:
inline void resize(const int &);
public:
BigInteger() : digits(nullptr), flag(true) { *this = 0; }
BigInteger(const BigInteger &x) : digits(nullptr) { *this = x; }
BigInteger(const long long &x) : digits(nullptr) { *this = x; }
BigInteger(const std::string &s) : digits(nullptr) { *this = s; }
BigInteger(const std::vector<bool> &b) : digits(nullptr) { *this = b; }
template <class BoolIt>
BigInteger(const BoolIt &begin, const BoolIt &end) : digits(nullptr) {
*this = std::vector<bool>(begin, end);
}
BigInteger &operator=(const BigInteger &);
BigInteger &operator=(const long long &);
BigInteger &operator=(const std::string &);
BigInteger &operator=(const std::vector<bool> &);
void clear();
~BigInteger() { clear(); }
friend std::ostream &operator<<(std::ostream &out, const BigInteger &x) {
if (!x.flag) out << '-';
out << (long long)x.digits[x.size];
for (int i = x.size - 1; i >= 1; i--)
out << std::setw(WIDTH) << std::setfill('0')
<< (long long)x.digits[i];
return out;
}
friend std::istream &operator>>(std::istream &in, BigInteger &x) {
std::string s;
in >> s;
x = s;
return in;
}
std::string to_string() const;
long long to_long_long() const;
std::vector<bool> to_binary() const;
BigInteger operator-() const;
BigInteger abs() const;
bool operator==(const BigInteger &) const;
#if __cplusplus >= 202002L
auto operator<=>(const BigInteger &) const;
#else
bool operator<(const BigInteger &) const;
bool operator>(const BigInteger &) const;
bool operator!=(const BigInteger &) const;
bool operator<=(const BigInteger &) const;
bool operator>=(const BigInteger &) const;
#endif //__cplusplus >= 202002L
BigInteger div2() const;
std::pair<BigInteger, BigInteger> divmod(const BigInteger &,
bool = false) const;
BigInteger operator+(const BigInteger &) const;
BigInteger operator-(const BigInteger &) const;
BigInteger operator*(const int &) const;
BigInteger operator*(const BigInteger &) const;
BigInteger operator/(const long long &) const;
BigInteger operator/(const BigInteger &) const;
BigInteger operator%(const long long &) const;
BigInteger operator%(const BigInteger &) const;
BigInteger pow(const long long &) const;
BigInteger pow(const long long &, const BigInteger &) const;
BigInteger root(const long long & = 2) const;
BigInteger gcd(const BigInteger &) const;
BigInteger lcm(const BigInteger &) const;
BigInteger &operator+=(const BigInteger &);
BigInteger &operator-=(const BigInteger &);
BigInteger &operator*=(int);
BigInteger &operator*=(const BigInteger &);
BigInteger &operator/=(const long long &);
BigInteger &operator/=(const BigInteger &);
BigInteger &operator%=(const long long &);
BigInteger &operator%=(const BigInteger &);
BigInteger operator<<(const long long &);
BigInteger operator>>(const long long &);
BigInteger &operator<<=(const long long &);
BigInteger &operator>>=(const long long &);
BigInteger operator&(const BigInteger &);
BigInteger operator|(const BigInteger &);
BigInteger operator^(const BigInteger &);
BigInteger &operator&=(const BigInteger &);
BigInteger &operator|=(const BigInteger &);
BigInteger &operator^=(const BigInteger &);
BigInteger &operator++();
BigInteger operator++(int);
BigInteger &operator--();
BigInteger operator--(int);
};
inline void BigInteger::push(const digit_t &val) {
if (size == capacity) {
int new_capacity = 0;
if (capacity < 1000)
new_capacity = capacity << 1;
else
new_capacity = (capacity >> 1) * 3;
if (new_capacity < 0) new_capacity = INT_MAX;
digit_t *new_digits = new digit_t[new_capacity + 1];
std::memcpy(new_digits, digits, sizeof(long long) * (capacity + 1));
delete[] digits;
digits = new_digits, capacity = new_capacity;
}
digits[++size] = val;
}
inline void BigInteger::pop() { digits[size--] = 0; }
inline int BigInteger::compare(const BigInteger &x) const {
if (flag && !x.flag) return 1;
if (!flag && x.flag) return -1;
int sgn = (flag && x.flag ? 1 : -1);
if (size > x.size) return sgn;
if (size < x.size) return -sgn;
for (int i = size; i >= 1; i--) {
if (digits[i] > x.digits[i]) return sgn;
if (digits[i] < x.digits[i]) return -sgn;
}
return 0;
}
inline void BigInteger::reserve(const int &sz) {
if (sz < 0) return;
if (digits != nullptr) delete[] digits;
capacity = sz, size = 0;
digits = new digit_t[sz + 1];
std::memset(digits, 0, sizeof(digit_t) * (sz + 1));
}
inline void BigInteger::resize(const int &sz) { reserve(sz), size = sz; }
BigInteger &BigInteger::operator=(const BigInteger &x) {
reserve(x.size + 1);
flag = x.flag, size = x.size;
std::memcpy(digits, x.digits, sizeof(digit_t) * (x.size + 1));
return *this;
}
BigInteger &BigInteger::operator=(const long long &x) {
flag = (x >= 0), reserve(4);
if (x == 0) return size = 1, digits[1] = 0, *this;
if (x == LLONG_MIN) return *this = "-9223372036854775808";
long long n = std::abs(x);
do {
push(n % BASE), n /= BASE;
} while (n);
return *this;
}
BigInteger &BigInteger::operator=(const std::string &s) {
flag = true, reserve(s.size() / WIDTH + 1);
if (s.empty() || s == "-") return *this = 0;
int i = 0;
if (s[0] == '-') flag = false, i++;
for (int j = s.size() - 1; j >= i; j -= WIDTH) {
int start = std::max(i, j - WIDTH + 1), len = j - start + 1;
push(std::stoll(s.substr(start, len)));
}
return *this;
}
BigInteger &BigInteger::operator=(const std::vector<bool> &b) {
*this = 0;
if (b.empty() || (b.size() == 1 && b[0] == 0)) return *this;
BigInteger pow2 = 1;
for (int i = b.size() - 1; i >= 0; i--, pow2 += pow2)
if (b[i]) *this += pow2;
return *this;
}
void BigInteger::clear() {
if (digits != nullptr) delete[] digits, digits = nullptr;
}
std::string BigInteger::to_string() const {
std::stringstream ss;
ss << *this;
return ss.str();
}
long long BigInteger::to_long_long() const { return std::stoll(to_string()); }
std::vector<bool> BigInteger::to_binary() const {
if (*this == 0) return {0};
std::vector<bool> res;
for (BigInteger x = *this; x != 0; x = x.div2())
res.emplace_back(x.digits[1] & 1);
std::reverse(res.begin(), res.end());
return res;
};
BigInteger BigInteger::operator-() const {
if (*this == 0) return 0;
BigInteger res = *this;
res.flag = !flag;
return res;
}
BigInteger BigInteger::abs() const {
BigInteger res = *this;
res.flag = true;
return res;
}
bool BigInteger::operator==(const BigInteger &x) const {
return compare(x) == 0;
}
#if __cplusplus >= 202002L
auto BigInteger::operator<=>(const BigInteger &x) const { return compare(x); }
#else
bool BigInteger::operator<(const BigInteger &x) const { return compare(x) < 0; }
bool BigInteger::operator>(const BigInteger &x) const { return compare(x) > 0; }
bool BigInteger::operator!=(const BigInteger &x) const {
return compare(x) != 0;
}
bool BigInteger::operator<=(const BigInteger &x) const {
return compare(x) <= 0;
}
bool BigInteger::operator>=(const BigInteger &x) const {
return compare(x) >= 0;
}
#endif //__cplusplus >= 202002L
BigInteger BigInteger::operator+(const BigInteger &x) const {
if (!x.flag) return *this - x.abs();
if (!flag) return x - abs();
BigInteger res;
res.flag = !(flag ^ x.flag);
int n = std::max(size, x.size) + 1;
res.reserve(n);
digit_t carry = 0;
for (int i = 1; i <= n; i++) {
digit_t d1 = i <= size ? digits[i] : 0,
d2 = i <= x.size ? x.digits[i] : 0;
res.push(d1 + d2 + carry);
carry = res.digits[i] / BASE;
res.digits[i] %= BASE;
}
while (res.size > 1 && res.digits[res.size] == 0) res.pop();
return res;
}
BigInteger BigInteger::operator-(const BigInteger &x) const {
if (!x.flag) return *this + x.abs();
if (!flag) return -(abs() + x);
BigInteger res;
if (*this < x) res.flag = false;
digit_t carry = 0;
int n = std::max(size, x.size);
res.reserve(n);
for (int i = 1; i <= n; i++) {
digit_t d1 = i <= size ? digits[i] : 0,
d2 = i <= x.size ? x.digits[i] : 0;
if (res.flag)
res.push(d1 - d2 - carry);
else
res.push(d2 - d1 - carry);
if (res.digits[i] < 0)
res.digits[i] += BASE, carry = 1;
else
carry = 0;
}
while (res.size > 1 && res.digits[res.size] == 0) res.pop();
return res;
}
namespace __FFT {
constexpr long long FFT_BASE = 1e4;
constexpr double PI2 = 6.283185307179586231995927;
constexpr double PI6 = 18.84955592153875869598778;
constexpr int RECALC_WIDTH = 10;
constexpr int RECALC_BASE = (1 << RECALC_WIDTH) - 1;
struct complex {
double real, imag;
complex(double x = 0.0, double y = 0.0) : real(x), imag(y) {}
complex operator+(const complex &other) const {
return complex(real + other.real, imag + other.imag);
}
complex operator-(const complex &other) const {
return complex(real - other.real, imag - other.imag);
}
complex operator*(const complex &other) const {
return complex(real * other.real - imag * other.imag,
real * other.imag + other.real * imag);
}
complex &operator+=(const complex &other) {
return real += other.real, imag += other.imag, *this;
}
complex &operator-=(const complex &other) {
return real -= other.real, imag -= other.imag, *this;
}
complex &operator*=(const complex &other) { return *this = *this * other; }
};
complex *arr = nullptr;
inline void init(int n) {
if (arr != nullptr) delete[] arr, arr = nullptr;
arr = new complex[n + 1];
}
template <const int n> inline void fft(complex *a) {
const int n2 = n >> 1, n4 = n >> 2;
complex w(1.0, 0.0), w3(1.0, 0.0);
const complex wn(std::cos(PI2 / n), std::sin(PI2 / n)),
wn3(std::cos(PI6 / n), std::sin(PI6 / n));
for (int i = 0; i < n4; i++, w *= wn, w3 *= wn3) {
if (!(i & RECALC_BASE))
w = complex(std::cos(PI2 * i / n), std::sin(PI2 * i / n)),
w3 = w * w * w;
complex x = a[i] - a[i + n2], y = a[i + n4] - a[i + n2 + n4];
y = complex(y.imag, -y.real);
a[i] += a[i + n2], a[i + n4] += a[i + n2 + n4];
a[i + n2] = (x - y) * w, a[i + n2 + n4] = (x + y) * w3;
}
fft<n2>(a), fft<n4>(a + n2), fft<n4>(a + n2 + n4);
}
template <> inline void fft<1>(complex *a) {}
template <> inline void fft<0>(complex *a) {}
template <> inline void fft<2>(complex *a) {
complex x = a[0], y = a[1];
a[0] += y, a[1] = x - y;
}
template <> inline void fft<4>(complex *a) {
complex a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
complex x = a0 - a2, y = a1 - a3;
y = complex(y.imag, -y.real);
a[0] += a2, a[1] += a3, a[2] = x - y, a[3] = x + y;
fft<2>(a);
}
template <const int n> inline void ifft(complex *a) {
const int n2 = n >> 1, n4 = n >> 2;
ifft<n2>(a), ifft<n4>(a + n2), ifft<n4>(a + n2 + n4);
complex w(1.0, 0.0), w3(1.0, 0.0);
const complex wn(std::cos(PI2 / n), -std::sin(PI2 / n)),
wn3(std::cos(PI6 / n), -std::sin(PI6 / n));
for (int i = 0; i < n4; i++, w *= wn, w3 *= wn3) {
if (!(i & RECALC_BASE))
w = complex(std::cos(PI2 * i / n), -std::sin(PI2 * i / n)),
w3 = w * w * w;
complex p = w * a[i + n2], q = w3 * a[i + n2 + n4];
complex x = a[i], y = p + q, x1 = a[i + n4], y1 = p - q;
y1 = complex(y1.imag, -y1.real);
a[i] += y, a[i + n4] += y1, a[i + n2] = x - y, a[i + n2 + n4] = x1 - y1;
}
}
template <> inline void ifft<1>(complex *a) {}
template <> inline void ifft<0>(complex *a) {}
template <> inline void ifft<2>(complex *a) {
complex x = a[0], y = a[1];
a[0] += y, a[1] = x - y;
}
template <> inline void ifft<4>(complex *a) {
ifft<2>(a);
complex p = a[2], q = a[3];
complex x = a[0], y = p + q, x1 = a[1], y1 = p - q;
y1 = complex(y1.imag, -y1.real);
a[0] += y, a[1] += y1, a[2] = x - y, a[3] = x1 - y1;
}
inline void dft(complex *a, int n) {
if (n <= 1) return;
switch (n) {
case 1 << 2:
fft<1 << 2>(a);
break;
case 1 << 3:
fft<1 << 3>(a);
break;
case 1 << 4:
fft<1 << 4>(a);
break;
case 1 << 5:
fft<1 << 5>(a);
break;
case 1 << 6:
fft<1 << 6>(a);
break;
case 1 << 7:
fft<1 << 7>(a);
break;
case 1 << 8:
fft<1 << 8>(a);
break;
case 1 << 9:
fft<1 << 9>(a);
break;
case 1 << 10:
fft<1 << 10>(a);
break;
case 1 << 11:
fft<1 << 11>(a);
break;
case 1 << 12:
fft<1 << 12>(a);
break;
case 1 << 13:
fft<1 << 13>(a);
break;
case 1 << 14:
fft<1 << 14>(a);
break;
case 1 << 15:
fft<1 << 15>(a);
break;
case 1 << 16:
fft<1 << 16>(a);
break;
case 1 << 17:
fft<1 << 17>(a);
break;
case 1 << 18:
fft<1 << 18>(a);
break;
case 1 << 19:
fft<1 << 19>(a);
break;
case 1 << 20:
fft<1 << 20>(a);
break;
case 1 << 21:
fft<1 << 21>(a);
break;
case 1 << 22:
fft<1 << 22>(a);
break;
case 1 << 23:
fft<1 << 23>(a);
break;
case 1 << 24:
fft<1 << 24>(a);
break;
case 1 << 25:
fft<1 << 25>(a);
break;
case 1 << 26:
fft<1 << 26>(a);
break;
case 1 << 27:
fft<1 << 27>(a);
break;
case 1 << 28:
fft<1 << 28>(a);
break;
case 1 << 29:
fft<1 << 29>(a);
break;
case 1 << 30:
fft<1 << 30>(a);
break;
case 1 << 31:
fft<1 << 31>(a);
break;
throw FFTLimitExceededError();
}
}
inline void idft(complex *a, int n) {
if (n <= 1) return;
switch (n) {
case 1 << 2:
ifft<1 << 2>(a);
break;
case 1 << 3:
ifft<1 << 3>(a);
break;
case 1 << 4:
ifft<1 << 4>(a);
break;
case 1 << 5:
ifft<1 << 5>(a);
break;
case 1 << 6:
ifft<1 << 6>(a);
break;
case 1 << 7:
ifft<1 << 7>(a);
break;
case 1 << 8:
ifft<1 << 8>(a);
break;
case 1 << 9:
ifft<1 << 9>(a);
break;
case 1 << 10:
ifft<1 << 10>(a);
break;
case 1 << 11:
ifft<1 << 11>(a);
break;
case 1 << 12:
ifft<1 << 12>(a);
break;
case 1 << 13:
ifft<1 << 13>(a);
break;
case 1 << 14:
ifft<1 << 14>(a);
break;
case 1 << 15:
ifft<1 << 15>(a);
break;
case 1 << 16:
ifft<1 << 16>(a);
break;
case 1 << 17:
ifft<1 << 17>(a);
break;
case 1 << 18:
ifft<1 << 18>(a);
break;
case 1 << 19:
ifft<1 << 19>(a);
break;
case 1 << 20:
ifft<1 << 20>(a);
break;
case 1 << 21:
ifft<1 << 21>(a);
break;
case 1 << 22:
ifft<1 << 22>(a);
break;
case 1 << 23:
ifft<1 << 23>(a);
break;
case 1 << 24:
ifft<1 << 24>(a);
break;
case 1 << 25:
ifft<1 << 25>(a);
break;
case 1 << 26:
ifft<1 << 26>(a);
break;
case 1 << 27:
ifft<1 << 27>(a);
break;
case 1 << 28:
ifft<1 << 28>(a);
break;
case 1 << 29:
ifft<1 << 29>(a);
break;
case 1 << 30:
ifft<1 << 30>(a);
break;
case 1 << 31:
ifft<1 << 31>(a);
break;
throw FFTLimitExceededError();
}
}
} // namespace __FFT
BigInteger BigInteger::fft_mul(const BigInteger &a, const BigInteger &b) {
static_assert(__FFT::FFT_BASE * __FFT::FFT_BASE == BASE);
int least = (a.size + b.size) << 1, lim = 1 << std::__lg(least);
if (lim < least) lim <<= 1;
__FFT::init(lim);
using __FFT::arr;
for (int i = 0; i < a.size; i++) {
arr[i << 1].real = a.digits[i + 1] % 10000;
arr[i << 1 | 1].real = a.digits[i + 1] / 10000 % 10000;
}
for (int i = 0; i < b.size; i++) {
arr[i << 1].imag = b.digits[i + 1] % 10000;
arr[i << 1 | 1].imag = b.digits[i + 1] / 10000 % 10000;
}
__FFT::dft(arr, lim);
for (int i = 0; i < lim; i++) arr[i] *= arr[i];
__FFT::idft(arr, lim);
BigInteger res;
res.resize(a.size + b.size + 1);
digit_t carry = 0;
double inv = 0.5 / lim;
for (int i = 0; i <= a.size + b.size; i++) {
carry += (digit_t)(arr[i << 1].imag * inv + 0.5);
carry += (digit_t)(arr[i << 1 | 1].imag * inv + 0.5) * 10000LL;
res.digits[i + 1] += carry % BASE, carry /= BASE;
}
while (res.size > 1 && res.digits[res.size] == 0) res.pop();
return res;
}
BigInteger BigInteger::operator*(const BigInteger &x) const {
BigInteger zero = 0;
if (*this == zero || x == zero) return zero;
int n = size, m = x.size;
long long lim = 1LL * n * m;
if (lim >= FFT_LIMIT) {
BigInteger res = fft_mul(*this, x);
res.flag = !(flag ^ x.flag);
return res;
}
BigInteger res;
res.flag = !(flag ^ x.flag);
res.resize(n + m + 2);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
res.digits[i + j - 1] += digits[i] * x.digits[j];
res.digits[i + j] += res.digits[i + j - 1] / BASE;
res.digits[i + j - 1] %= BASE;
}
}
for (int i = 1; i <= n + m + 1; i++) {
res.digits[i + 1] += res.digits[i] / BASE;
res.digits[i] %= BASE;
}
while (res.size > 1 && res.digits[res.size] == 0) res.pop();
return res;
}
BigInteger &BigInteger::operator*=(int x) {
if (x == 0 || *this == 0) return *this = 0;
if (x < 0) flag = !flag, x = -x;
digit_t carry = 0;
for (int i = 1; i <= size || carry; i++) {
if (i > size) push(0);
digit_t cur = digits[i] * x + carry;
carry = cur / BigInteger::BASE;
digits[i] = cur % BigInteger::BASE;
}
while (size > 1 && digits[size] == 0) pop();
return *this;
}
BigInteger BigInteger::operator*(const int &x) const {
BigInteger t = *this;
return t *= x;
}
BigInteger BigInteger::div2() const {
BigInteger res = *this;
for (int i = size; i >= 1; i--) {
if ((res.digits[i] & 1) && (i > 1)) res.digits[i - 1] += BASE;
res.digits[i] >>= 1;
}
while (res.size > 1 && res.digits[res.size] == 0) res.pop();
return res;
}
BigInteger BigInteger::operator/(const long long &x) const {
if (x == 0) throw -1;
if (*this == 0) return 0;
if (x == 2) return div2();
if (x == -2) {
BigInteger res = div2();
res.flag = !res.flag;
return res;
}
BigInteger res;
res.flag = !(flag ^ (x >= 0));
digit_t cur = 0, div = std::abs(x);
res.resize(size);
for (int i = size; i >= 1; i--) {
cur = cur * BASE + digits[i];
res.digits[i] = res.flag ? (cur / div) : (-cur / -div);
cur %= div;
}
while (res.size > 1 && res.digits[res.size] == 0) res.pop();
return res;
}
inline BigInteger BigInteger::move_r(int d) const {
if (*this == 0 || d >= size) return 0;
if (d == 0) return *this;
BigInteger res;
res.reserve(size - d + 1);
for (int i = d + 1; i <= size; i++) res.push(digits[i]);
return res;
}
inline BigInteger BigInteger::move_l(int d) const {
if (*this == 0) return 0;
if (d == 0) return *this;
BigInteger res;
res.reserve(size + d + 1);
for (int i = 1; i <= d; i++) res.push(0);
for (int i = 1; i <= size; i++) res.push(digits[i]);
return res;
}
BigInteger BigInteger::newton_inv(int n) const {
if (*this == 0) throw ZeroDivisionError();
if (std::min(size, n - size) <= NEWTON_MIN_LEVEL) {
BigInteger a;
a.resize(n + 1);
std::memset(a.digits, 0, sizeof(digit_t) * a.size);
a.digits[n + 1] = 1;
return a.divmod(*this, true).first;
}
int k = (n - size + 5) >> 1, k2 = k > size ? 0 : size - k;
BigInteger x = move_r(k2);
int n2 = k + x.size;
BigInteger y = x.newton_inv(n2), a = y + y, b = (*this) * y * y;
return a.move_l(n - n2 - k2) - b.move_r(2 * (n2 + k2) - n) - 1;
}
std::pair<BigInteger, BigInteger>
BigInteger::newton_div(const BigInteger &x) const {
int k = size - x.size + 5, k2 = k > x.size ? 0 : x.size - k;
BigInteger x2 = x.move_r(k2);
if (k2 != 0) x2 += 1;
int n2 = k + x2.size;
BigInteger u = (*this) * x2.newton_inv(n2);
BigInteger q = u.move_r(n2 + k2), r = (*this) - q * x;
while (r >= x) q += 1, r -= x;
return std::make_pair(q, r);
}
std::pair<BigInteger, BigInteger> BigInteger::divmod(const BigInteger &x,
bool dis_newton) const {
static const int base = BigInteger::BASE;
BigInteger a = abs(), b = x.abs();
if (b == 0) throw ZeroDivisionError();
if (a < b) return std::make_pair(0, flag ? a : -a);
if (!dis_newton && size > NEWTON_LIMIT) return newton_div(x);
int t = base / (x.digits[x.size] + 1);
a *= t, b *= t;
int n = a.size, m = b.size;
BigInteger q = 0, r = 0;
q.resize(n);
for (int i = n; i >= 1; i--) {
r *= base, r += a.digits[i];
digit_t d1 = m < r.size ? r.digits[m + 1] : 0,
d2 = m - 1 < r.size ? r.digits[m] : 0;
int d = (d1 * base + d2) / b.digits[m];
r -= b * d;
while (!r.flag) r += b, d--;
q.digits[i] = d;
}
q.flag = !(flag ^ x.flag), r.flag = flag;
while (q.size > 1 && q.digits[q.size] == 0) q.pop();
return std::make_pair(q, r / t);
}
BigInteger BigInteger::operator/(const BigInteger &x) const {
return divmod(x).first;
}
BigInteger BigInteger::operator%(const long long &x) const {
if (x == 2) return digits[1] & 1;
if (x == 5) return digits[1] % 5;
return *this - (*this / x * x);
}
BigInteger BigInteger::operator%(const BigInteger &x) const {
return divmod(x).second;
}
BigInteger BigInteger::pow(const long long &x) const {
BigInteger res = 1, a = *this;
for (long long t = x; t != 0; t >>= 1) {
if (t & 1) res *= a;
a *= a;
}
return res;
}
BigInteger BigInteger::pow(const long long &x, const BigInteger &p) const {
BigInteger res = 1, a = *this % p;
for (long long t = x; t != 0; t >>= 1) {
if (t & 1) res = res * a % p;
a = a * a % p;
}
return res;
}
BigInteger BigInteger::root(const long long &m) const {
if (*this == 0 || m == 1) return *this;
static constexpr long long base = BigInteger::BASE;
BigInteger n = *this, t = base, x = std::min(n, t.move_l((n.size + m) / m));
int l = 0, r = base - 1;
while (l < r) {
int mid = (l + r) >> 1;
x.digits[x.size] = mid;
if (x.pow(m) <= n)
l = mid + 1;
else
r = mid;
}
x.digits[x.size] = l;
while (x.size > 1 && x.digits[x.size] == 0) x.pop();
BigInteger x2 = (x * (m - 1) + n / x.pow(m - 1)) / m;
while (x2 < x) std::swap(x2, x), x2 = (x * (m - 1) + n / x.pow(m - 1)) / m;
return x;
}
BigInteger BigInteger::gcd(const BigInteger &x) const {
BigInteger a = *this, b = x;
if (a < b) std::swap(a, b);
if (b == 0) return a;
int t = 0;
while (a % 2 == 0 && b % 2 == 0) a = a.div2(), b = b.div2(), t++;
while (b > 0) {
if (a % 2 == 0)
a = a.div2();
else if (b % 2 == 0)
b = b.div2();
else
a -= b;
if (a < b) std::swap(a, b);
}
while (t--) a += a;
return a;
}
BigInteger BigInteger::lcm(const BigInteger &x) const {
return *this / gcd(x) * x;
}
BigInteger &BigInteger::operator+=(const BigInteger &x) {
return *this = *this + x;
}
BigInteger &BigInteger::operator-=(const BigInteger &x) {
return *this = *this - x;
}
BigInteger &BigInteger::operator*=(const BigInteger &x) {
return *this = *this * x;
}
BigInteger &BigInteger::operator/=(const long long &x) {
return *this = *this / x;
}
BigInteger &BigInteger::operator/=(const BigInteger &x) {
return *this = *this / x;
}
BigInteger &BigInteger::operator%=(const long long &x) {
return *this = *this / x;
}
BigInteger &BigInteger::operator%=(const BigInteger &x) {
return *this = *this % x;
}
BigInteger BigInteger::operator<<(const long long &x) {
if (x <= 0) return *this;
BigInteger res = *this;
for (long long i = 1; i <= x; i++) res += res;
return res;
}
BigInteger BigInteger::operator>>(const long long &x) {
if (x <= 0) return *this;
BigInteger res = *this;
for (long long i = 1; i <= x; i++) res = res.div2();
return res;
}
BigInteger &BigInteger::operator<<=(const long long &x) {
return *this = *this << x;
}
BigInteger &BigInteger::operator>>=(const long long &x) {
return *this = *this >> x;
}
template <class F>
inline BigInteger BigInteger::binary_op_helper(const BigInteger &x,
const BigInteger &y,
const F &func) {
auto to_bin = [](BigInteger x) -> std::vector<bool> {
if (x == 0) return {0};
std::vector<bool> res;
for (; x != 0; x = x.div2()) res.emplace_back(x.digits[1] & 1);
return res;
};
std::vector<bool> a = to_bin(x), b = to_bin(y);
int n = a.size(), m = b.size(), lim = std::max(n, m);
std::vector<bool> res(lim, 0);
for (int i = lim - 1; i >= 0; i--)
res[i] = func(i < n ? a[i] : 0, i < m ? b[i] : 0);
std::reverse(res.begin(), res.end());
return res;
}
BigInteger BigInteger::operator&(const BigInteger &x) {
return binary_op_helper(*this, x,
[](bool a, bool b) -> bool { return a & b; });
}
BigInteger BigInteger::operator|(const BigInteger &x) {
return binary_op_helper(*this, x,
[](bool a, bool b) -> bool { return a | b; });
}
BigInteger BigInteger::operator^(const BigInteger &x) {
return binary_op_helper(*this, x,
[](bool a, bool b) -> bool { return a ^ b; });
}
BigInteger &BigInteger::operator&=(const BigInteger &x) {
return *this = *this & x;
}
BigInteger &BigInteger::operator|=(const BigInteger &x) {
return *this = *this | x;
}
BigInteger &BigInteger::operator^=(const BigInteger &x) {
return *this = *this ^ x;
}
BigInteger &BigInteger::operator++() { return *this += 1; }
BigInteger BigInteger::operator++(int) {
BigInteger t = *this;
return *this += 1, t;
}
BigInteger &BigInteger::operator--() { return *this -= 1; }
BigInteger BigInteger::operator--(int) {
BigInteger t = *this;
return *this -= 1, t;
}
// END_NOLINT
} // namespace BigInteger
using BigInt = BigInteger::BigInteger;
#define int i64
constexpr int INF = 1e18;
void solve() {
BigInt n; int m;
cin >> n >> m;
string sn = n.to_string();
int md = 0;
for (char c: sn) {
md = (md * 10 + c - '0') % m;
}
BigInt ans = n + m - md;
array<BigInt, 24> pw10{1};
for (int i = 1; i < 24; i++) pw10[i] = pw10[i - 1] * 10;
string sm = to_string(m);
for (int b = 0; b < 12; b++) {
BigInt trailing = pw10[b] * m;
int trailing_len = sm.length() + b;
BigInt trailing_n;
if (trailing_len <= sn.length()) trailing_n = sn.substr(sn.length() - trailing_len, trailing_len);
else trailing_n = n;
BigInt new_ans = n - trailing_n + trailing;
if (trailing_n >= trailing) new_ans += pw10[trailing_len];
if (new_ans < ans) ans = new_ans;
}
debug(ans);
n++;
sn = n.to_string();
for (int b = 0; b < 12; b++) {
if (sn.length() > b && sn.substr(sn.length() - b, b) == string(b, '0')) {
;
} else {
BigInt trailing = sn.substr(sn.length() - b, b);
n = n - trailing + pw10[b];
sn = n.to_string();
}
if (sn.find(sm) != string::npos) if (n < ans) {
ans = n;
}
}
cout << ans << '\n';
}
#undef int
// Make bold hypotheses and verify carefully
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
};
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3816kb
input:
6 7 3 12 3 9 10 249 51 1369 37 2 1
output:
9 13 10 251 1370 3
result:
ok 6 lines
Test #2:
score: 0
Accepted
time: 1097ms
memory: 3904kb
input:
100000 3196282243 28 7614814237 33 2814581084 97 1075124401 58 7822266214 100 1767317768 31 7189709841 75 9061337538 69 6552679231 38 9946082148 18 5497675062 54 7787300351 65 4310767261 68 4811341953 100 3265496130 31 8294404054 62 2845521744 90 1114254672 26 6442013672 13 3744046866 40 3289624367 ...
output:
3196282244 7614814251 2814581097 1075124424 7822266300 1767317769 7189709850 9061337569 6552679238 9946082160 5497675063 7787300365 4310767268 4811342000 3265496131 8294404062 2845521790 1114254674 6442013673 3744046867 3289624375 6477935360 1292587551 5504674689 2898829180 7882736025 2846033387 923...
result:
ok 100000 lines
Test #3:
score: 0
Accepted
time: 1288ms
memory: 3836kb
input:
100000 81390699571930639918 18 48435143897560239761 20 51628960043353404809 75 47871552664477358704 12 59273263135375104780 37 76916933870890715781 71 23716799616473386311 99 68152894841119747794 73 87132912926681514765 23 14152130046962902029 76 46737628796812988809 24 40572731276115804589 44 26281...
output:
81390699571930639920 48435143897560239780 51628960043353404825 47871552664477358712 59273263135375104781 76916933870890715782 23716799616473386312 68152894841119747819 87132912926681514784 14152130046962902060 46737628796812988824 40572731276115804612 26281826064684565884 31440839508345860244 322404...
result:
ok 100000 lines
Test #4:
score: 0
Accepted
time: 265ms
memory: 3948kb
input:
3000 7455619882273084107817302538515753878442453229160411398764628307708900718973255504130291326067024207515690930909093270962092669445260372092520050302437090344417275699335988483584829739890137897388569114922455183012826259500289116227868472807384706143668392682061768042886347879057062217228560088...
output:
745561988227308410781730253851575387844245322916041139876462830770890071897325550413029132606702420751569093090909327096209266944526037209252005030243709034441727569933598848358482973989013789738856911492245518301282625950028911622786847280738470614366839268206176804288634787905706221722856008829738...
result:
ok 3000 lines
Test #5:
score: 0
Accepted
time: 239ms
memory: 4216kb
input:
30 744510720233756810275704474604569745531035132640480367036243214564743016462196305795005354253050610470663589619681077004760475741831076832118956334526511556189341001350810877421229216943948759000423729628987372479322027768925371301094347427331321252113757179047865411408129452046409100799804797802...
output:
744510720233756810275704474604569745531035132640480367036243214564743016462196305795005354253050610470663589619681077004760475741831076832118956334526511556189341001350810877421229216943948759000423729628987372479322027768925371301094347427331321252113757179047865411408129452046409100799804797802630...
result:
ok 30 lines
Test #6:
score: 0
Accepted
time: 263ms
memory: 4216kb
input:
30 105809806761073271256887955844712146828376005200803410278562148742151831107043468856832007772397456498455138267388212588031778017994162605374749926516470689670500596864238694115641474868867283410369346289694466106606968664652794746652928273585660548259964572696052192486090603389036781439603103550...
output:
105809806761073271256887955844712146828376005200803410278562148742151831107043468856832007772397456498455138267388212588031778017994162605374749926516470689670500596864238694115641474868867283410369346289694466106606968664652794746652928273585660548259964572696052192486090603389036781439603103550889...
result:
ok 30 lines
Test #7:
score: 0
Accepted
time: 292ms
memory: 11048kb
input:
3 6662543589767466036246495639712784214474800991502397969575900509392047845463534421346617412312874112216857204224202275839595569716788606196210901109061789975871578517491994493982488930577332027254701120487517960025453194037512904252125592964194448410502834649100626540616447074805775399798416968996...
output:
666254358976746603624649563971278421447480099150239796957590050939204784546353442134661741231287411221685720422420227583959556971678860619621090110906178997587157851749199449398248893057733202725470112048751796002545319403751290425212559296419444841050283464910062654061644707480577539979841696899669...
result:
ok 3 lines
Test #8:
score: 0
Accepted
time: 246ms
memory: 11196kb
input:
3 2256815269292565600156592193265637162224642022040502404316754847487816065925979403817785481924286639616366305614486960621565248701689067791722502719550041520364571182248705842386853601004910941840817347333021115646730530046766144383475985584378580286873533357460940983992705079090280123003684728456...
output:
225681526929256560015659219326563716222464202204050240431675484748781606592597940381778548192428663961636630561448696062156524870168906779172250271955004152036457118224870584238685360100491094184081734733302111564673053004676614438347598558437858028687353335746094098399270507909028012300368472845644...
result:
ok 3 lines
Test #9:
score: 0
Accepted
time: 285ms
memory: 3736kb
input:
3000 1207038022435933497172867897608582834259296434513291920701948658102620971426545864576004516739100232550813726497575096647995838994831563955620812388750705335658097405810012745415674568116125791908722845971700778242654229220680637480729636188583094437004798976145084978037723467998680024921907308...
output:
120703802243593349717286789760858283425929643451329192070194865810262097142654586457600451673910023255081372649757509664799583899483156395562081238875070533565809740581001274541567456811612579190872284597170077824265422922068063748072963618858309443700479897614508497803772346799868002492190730846477...
result:
ok 3000 lines
Test #10:
score: 0
Accepted
time: 286ms
memory: 3724kb
input:
3000 5187892603368075393366934145761537065733813260653168421673419435040503882271162798390450740194183522231455416476478191713916592902549286209613912969893791259298651451942049981218891583442405056389087471219061688102180898906527834095792495015886014196868276353417569226991138737552057896779213092...
output:
518789260336807539336693414576153706573381326065316842167341943504050388227116279839045074019418352223145541647647819171391659290254928620961391296989379125929865145194204998121889158344240505638908747121906168810218089890652783409579249501588601419686827635341756922699113873755205789677921309299202...
result:
ok 3000 lines
Test #11:
score: 0
Accepted
time: 1011ms
memory: 3632kb
input:
100000 6826989967 99 7841681495 15 3418122299 23 1701647194 72 9299999983 93 1881999956 82 1123299980 33 3771371885 19 1309999986 31 3877999989 78 9357331671 75 7627599957 76 1678299927 83 8841256998 57 8260576238 25 1799999994 18 3154099999 41 9276743997 44 4591431162 68 3499999996 35 8003134976 35...
output:
6826989968 7841681500 3418122300 1701647200 9299999993 1881999958 1123300000 3771371900 1310000000 3878000000 9357331675 7627599958 1678299983 8841257000 8260576250 1800000000 3154100000 9276744000 4591431168 3500000000 8003135000 5504020000 1255390000 4126500000 6300000000 7478000000 5763230000 666...
result:
ok 100000 lines
Test #12:
score: 0
Accepted
time: 1076ms
memory: 3832kb
input:
100000 4044835167 404504 8453174053 180343 2345170166 345322 8666517296 666590 8889410862 895103 6539631279 398778 8763575235 742233 3347416626 347507 6020459808 204689 2518651157 186574 1970898496 970950 3644468912 446818 2284133423 265848 4297464212 297490 9673618882 687317 2262910438 26292 460442...
output:
4045040000 8453180343 2345322000 8666590000 8889510300 6539877800 8763742233 3347507000 6020468900 2518657400 1970950000 3644681800 2284166016 4297490000 9673687317 2262920000 4604460456 5602450000 9441133300 9662607060 1137808896 5763236104 1265770000 9709569000 2270400726 8750103140 4985572109 607...
result:
ok 100000 lines
Test #13:
score: 0
Accepted
time: 597ms
memory: 3628kb
input:
30000 2258423372953702192256514103021059999999999999999999999999999999999999999999999999999999999942889028 410302106 9236851817519460666717196537240869999999999999999999999999999999999999999999999999999999999883401708 653724087 528305359636938134447446654161626435106860486355385047059638284973309516...
output:
2258423372953702192256514103021060000000000000000000000000000000000000000000000000000000000000000000 9236851817519460666717196537240870000000000000000000000000000000000000000000000000000000000000000000 52830535963693813444744665416162643510686048635538504705963828497330951691000000000000000000000000...
result:
ok 30000 lines
Test #14:
score: 0
Accepted
time: 272ms
memory: 3892kb
input:
3000 5922323879507505766800528767037919597502198414242047957236861868104971055619344440437107671176937451514382066899903609033675738466227459315946342972297607721778919880762618920008986787526795904399466415526677955192892547202914540028866220838677781672961400903843675918899999999999999999999999999...
output:
592232387950750576680052876703791959750219841424204795723686186810497105561934444043710767117693745151438206689990360903367573846622745931594634297229760772177891988076261892000898678752679590439946641552667795519289254720291454002886622083867778167296140090384367591890000000000000000000000000000000...
result:
ok 3000 lines
Test #15:
score: 0
Accepted
time: 233ms
memory: 3736kb
input:
300 79503684358998967099842390859918474661077381309414120162088118845509995775769599862634805068256914519241333788469171358889239210321345976686972530426806265499919511256567835592757432091301073156228966702566684249419578352892680950286666144449266128886167409392158527498584296552596909871547436747...
output:
795036843589989670998423908599184746610773813094141201620881188455099957757695998626348050682569145192413337884691713588892392103213459766869725304268062654999195112565678355927574320913010731562289667025666842494195783528926809502866661444492661288861674093921585274985842965525969098715474367473579...
result:
ok 300 lines
Test #16:
score: 0
Accepted
time: 251ms
memory: 4224kb
input:
30 963989556914230908082271728546945777135479223654091867288007126245836594537638569203178109698540536134315332558020645906558121951862746368709679951030471570045529976669887496328009080338319231117849873217415406534659827460233181034192437276876779118787074109399261707873162971159516672507806779438...
output:
963989556914230908082271728546945777135479223654091867288007126245836594537638569203178109698540536134315332558020645906558121951862746368709679951030471570045529976669887496328009080338319231117849873217415406534659827460233181034192437276876779118787074109399261707873162971159516672507806779438881...
result:
ok 30 lines
Test #17:
score: 0
Accepted
time: 266ms
memory: 11060kb
input:
3 5251523982592970506228422825473158460046709412102650259324461772573819982478268554863488566358166621796735028520826739449136398485099429491505550466187845809470304336668405076216439622257295011604734741380276770594862747289699140439236774183654203024248651235112580263413687129799928450508420430094...
output:
525152398259297050622842282547315846004670941210265025932446177257381998247826855486348856635816662179673502852082673944913639848509942949150555046618784580947030433666840507621643962225729501160473474138027677059486274728969914043923677418365420302424865123511258026341368712979992845050842043009466...
result:
ok 3 lines
Test #18:
score: 0
Accepted
time: 128ms
memory: 4064kb
input:
30 627919418377410357943555763628655192389689054924973950611879805274209177346126760861588844600423459519850583010250101760720518969321844870291790270120612460050314573390014064010258558280381655682905366739760793312813232203778926302125707670987782450886207303011675839927569831089665011115588292404...
output:
627919418377410357943555763628655192389689054924973950611879805274209177346126760861588844600423459519850583010250101760720518969321844870291790270120612460050314573390014064010258558280381655682905366739760793312813232203778926302125707670987782450886207303011675839927569831089665011115588292404149...
result:
ok 30 lines
Test #19:
score: 0
Accepted
time: 142ms
memory: 4276kb
input:
30 764080955258682719471086701870262765599374530101516574475330551922255442091459958688289946340233580617988205812251968123424819960658592846247598815326003118826452825551875685355929397031899182527979539632844954405219059237546143875107808300965485161976399348689613744946767210379782917080998523510...
output:
764080955258682719471086701870262765599374530101516574475330551922255442091459958688289946340233580617988205812251968123424819960658592846247598815326003118826452825551875685355929397031899182527979539632844954405219059237546143875107808300965485161976399348689613744946767210379782917080998523510627...
result:
ok 30 lines
Test #20:
score: 0
Accepted
time: 185ms
memory: 11068kb
input:
3 6028978024074413159342407738765076385763911038536831317696787959027528197366178750790544749013673661567582902671539726842479448599455873905708255453884865704773086705053235875806914264836730112475075045703811837740246613047422355645457818355939368587060246878107326418339579284201653817689773671953...
output:
602897802407441315934240773876507638576391103853683131769678795902752819736617875079054474901367366156758290267153972684247944859945587390570825545388486570477308670505323587580691426483673011247507504570381183774024661304742235564545781835593936858706024687810732641833957928420165381768977367195319...
result:
ok 3 lines
Test #21:
score: 0
Accepted
time: 167ms
memory: 11276kb
input:
3 5021181897690139043423621132705730237575386907971979814912425232029109374214407872841234899499833146294421742332452796878337581201268864699781904270882612294625097518085924677142481018311453949030110398429573396190105839011124187467223158307238425121693199936952649840784178844249496013886360158949...
output:
502118189769013904342362113270573023757538690797197981491242523202910937421440787284123489949983314629442174233245279687833758120126886469978190427088261229462509751808592467714248101831145394903011039842957339619010583901112418746722315830723842512169319993695264984078417884424949601388636015894947...
result:
ok 3 lines
Test #22:
score: 0
Accepted
time: 1002ms
memory: 3836kb
input:
100000 983 89 38 751 34 201 841 39 453 873 674 65 560 216 914 644 670 345 622 518 583 938 137 719 359 78 448 860 741 907 236 629 893 549 844 999 63 345 320 66 990 723 215 467 665 24 682 756 853 604 262 160 153 30 278 31 232 631 495 360 347 519 259 906 541 992 167 33 661 233 908 720 55 332 17 153 595...
output:
989 751 201 858 873 715 648 1288 690 1036 938 719 378 860 907 629 1098 999 345 330 1446 467 672 756 1208 320 180 279 631 720 519 906 992 198 699 1440 332 153 752 206 1534 1188 977 1142 1232 741 754 482 891 504 376 921 852 658 974 700 266 792 500 897 976 570 1258 869 120 578 616 1274 1240 860 453 229...
result:
ok 100000 lines
Test #23:
score: 0
Accepted
time: 1005ms
memory: 3696kb
input:
100000 145493 709877 915888 170549 680394 2504 24665 758139 242644 365499 994789 535590 518365 297247 852392 834337 480961 945750 485671 126953 262033 11673 199902 473744 91856 743475 779195 394619 60537 616388 570144 756645 285494 510464 298148 932570 110058 627373 686867 469501 82153 559208 231338...
output:
709877 1023294 681088 758139 365499 1071180 594494 1668674 945750 507812 268479 473744 743475 789238 616388 756645 510464 932570 627373 939002 559208 272262 957378 749236 980046 1307232 883500 695250 1351682 495376 391899 1403758 674864 399172 826044 486136 797852 368134 1341368 476373 998655 234605...
result:
ok 100000 lines
Test #24:
score: 0
Accepted
time: 1046ms
memory: 3840kb
input:
100000 22102638 716270982 114744220 553198855 952648509 973042933 12679271 411855162 766516692 376478639 797071538 701616593 832850102 567088052 350649206 231532599 950645496 638081144 879396229 769653386 7765699 641178981 664333826 683883038 953508821 193902679 470742245 399344120 571075073 4774108...
output:
716270982 553198855 973042933 411855162 1129435917 1403233186 1134176104 463065198 1276162288 1539306772 641178981 683883038 969513395 798688240 954821692 885018278 759825152 720908055 304133428 841067258 1086439989 172971588 1018041974 1194071806 1186808712 1520671194 1640903698 406899456 841206665...
result:
ok 100000 lines
Test #25:
score: 0
Accepted
time: 1079ms
memory: 3652kb
input:
100000 223876976 28 826504481 32 636375005 4 96535351 65 198842419 24 831169545 73 576953641 82 935299711 20 387543800 23 179825475 79 473820636 86 461889861 8 534725270 34 388928056 62 64278765 63 549355282 3 708135976 13 290272912 29 411662229 49 516874672 54 115846918 82 627529269 63 23910223 33 ...
output:
223876996 826504512 636375008 96535352 198842420 831169573 576953682 935299720 387543813 179825476 473820686 461889862 534725271 388928062 64278774 549355283 708135977 290272913 411662230 516874716 115846976 627529329 23910233 590830376 319867594 585259345 740335580 846844351 652565836 303759440 212...
result:
ok 100000 lines
Test #26:
score: 0
Accepted
time: 996ms
memory: 3640kb
input:
100000 95 410302106 52 820706056 67 87747886 43 380552276 40 627914953 23 374682702 8 733202611 86 386357954 3 550477660 64 659482338 63 766955734 79 625128385 13 406562646 8 777253591 37 653724087 100 107364480 58 953592822 68 213009532 67 302548407 41 282013297 95 228056767 92 407864420 18 1265642...
output:
410302106 820706056 87747886 380552276 627914953 374682702 733202611 386357954 550477660 659482338 766955734 625128385 406562646 777253591 653724087 107364480 953592822 213009532 302548407 282013297 228056767 407864420 126564216 867640132 89634672 168202079 693460954 910218987 330951691 513234559 11...
result:
ok 100000 lines
Test #27:
score: 0
Accepted
time: 999ms
memory: 3840kb
input:
99856 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 6...
output:
2 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok 99856 lines
Test #28:
score: 0
Accepted
time: 116ms
memory: 10116kb
input:
3 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
output:
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
ok 3 lines
Test #29:
score: 0
Accepted
time: 141ms
memory: 11292kb
input:
3 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
output:
999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
result:
ok 3 lines
Test #30:
score: 0
Accepted
time: 248ms
memory: 3624kb
input:
24573 1 1000000000 2 1000000000 3 1000000000 4 1000000000 5 1000000000 6 1000000000 7 1000000000 8 1000000000 9 1000000000 10 1000000000 11 1000000000 12 1000000000 13 1000000000 14 1000000000 15 1000000000 16 1000000000 17 1000000000 18 1000000000 19 1000000000 20 1000000000 21 1000000000 22 100000...
output:
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100...
result:
ok 24573 lines
Test #31:
score: 0
Accepted
time: 156ms
memory: 11052kb
input:
3 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
output:
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
ok 3 lines
Test #32:
score: 0
Accepted
time: 481ms
memory: 11216kb
input:
3 8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888...
output:
888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888...
result:
ok 3 lines
Extra Test:
score: 0
Extra Test Passed