QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#243186#6694. Math ProblemmaspyAC ✓965ms3896kbC++2014.3kb2023-11-07 21:52:072023-11-07 21:52:07

Judging History

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

  • [2023-11-07 21:52:07]
  • 评测
  • 测评结果:AC
  • 用时:965ms
  • 内存:3896kb
  • [2023-11-07 21:52:07]
  • 提交

answer

#line 1 "library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'000'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;

using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) overload3(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)

#define FOR_subset(t, s) \
  for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
int popcnt_mod_2(int x) { return __builtin_parity(x); }
int popcnt_mod_2(u32 x) { return __builtin_parity(x); }
int popcnt_mod_2(ll x) { return __builtin_parityll(x); }
int popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T, typename U>
T ceil(T x, U y) {
  return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U>
T floor(T x, U y) {
  return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T, typename U>
pair<T, T> divmod(T x, U y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template <typename T, typename U>
T SUM(const vector<U> &A) {
  T sum = 0;
  for (auto &&a: A) sum += a;
  return sum;
}

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  assert(!que.empty());
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  assert(!que.empty());
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
  }
  return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
  FOR(iter) {
    double x = (ok + ng) / 2;
    tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
  }
  return (ok + ng) / 2;
}

template <class T, class S>
inline bool chmax(T &a, const S &b) {
  return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
  return (a > b ? a = b, 1 : 0);
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  FOR(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
  int N = A.size();
  vector<T> B(N + 1);
  FOR(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vector<int> argsort(const vector<T> &A) {
  vector<int> ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](int i, int j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
  vc<T> B(len(I));
  FOR(i, len(I)) B[i] = A[I[i]];
  return B;
}
#endif
#line 1 "library/other/io.hpp"
// based on yosupo's fastio
#include <unistd.h>

namespace fastio {
#define FASTIO
// クラスが read(), print() を持っているかを判定するメタ関数
struct has_write_impl {
  template <class T>
  static auto check(T &&x) -> decltype(x.write(), std::true_type{});

  template <class T>
  static auto check(...) -> std::false_type;
};

template <class T>
class has_write : public decltype(has_write_impl::check<T>(std::declval<T>())) {
};

struct has_read_impl {
  template <class T>
  static auto check(T &&x) -> decltype(x.read(), std::true_type{});

  template <class T>
  static auto check(...) -> std::false_type;
};

template <class T>
class has_read : public decltype(has_read_impl::check<T>(std::declval<T>())) {};

struct Scanner {
  FILE *fp;
  char line[(1 << 15) + 1];
  size_t st = 0, ed = 0;
  void reread() {
    memmove(line, line + st, ed - st);
    ed -= st;
    st = 0;
    ed += fread(line + ed, 1, (1 << 15) - ed, fp);
    line[ed] = '\0';
  }
  bool succ() {
    while (true) {
      if (st == ed) {
        reread();
        if (st == ed) return false;
      }
      while (st != ed && isspace(line[st])) st++;
      if (st != ed) break;
    }
    if (ed - st <= 50) {
      bool sep = false;
      for (size_t i = st; i < ed; i++) {
        if (isspace(line[i])) {
          sep = true;
          break;
        }
      }
      if (!sep) reread();
    }
    return true;
  }
  template <class T, enable_if_t<is_same<T, string>::value, int> = 0>
  bool read_single(T &ref) {
    if (!succ()) return false;
    while (true) {
      size_t sz = 0;
      while (st + sz < ed && !isspace(line[st + sz])) sz++;
      ref.append(line + st, sz);
      st += sz;
      if (!sz || st != ed) break;
      reread();
    }
    return true;
  }
  template <class T, enable_if_t<is_integral<T>::value, int> = 0>
  bool read_single(T &ref) {
    if (!succ()) return false;
    bool neg = false;
    if (line[st] == '-') {
      neg = true;
      st++;
    }
    ref = T(0);
    while (isdigit(line[st])) { ref = 10 * ref + (line[st++] & 0xf); }
    if (neg) ref = -ref;
    return true;
  }
  template <typename T,
            typename enable_if<has_read<T>::value>::type * = nullptr>
  inline bool read_single(T &x) {
    x.read();
    return true;
  }
  bool read_single(double &ref) {
    string s;
    if (!read_single(s)) return false;
    ref = std::stod(s);
    return true;
  }
  bool read_single(char &ref) {
    string s;
    if (!read_single(s) || s.size() != 1) return false;
    ref = s[0];
    return true;
  }
  template <class T>
  bool read_single(vector<T> &ref) {
    for (auto &d: ref) {
      if (!read_single(d)) return false;
    }
    return true;
  }
  template <class T, class U>
  bool read_single(pair<T, U> &p) {
    return (read_single(p.first) && read_single(p.second));
  }
  template <size_t N = 0, typename T>
  void read_single_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
      auto &x = std::get<N>(t);
      read_single(x);
      read_single_tuple<N + 1>(t);
    }
  }
  template <class... T>
  bool read_single(tuple<T...> &tpl) {
    read_single_tuple(tpl);
    return true;
  }
  void read() {}
  template <class H, class... T>
  void read(H &h, T &... t) {
    bool f = read_single(h);
    assert(f);
    read(t...);
  }
  Scanner(FILE *fp) : fp(fp) {}
};

struct Printer {
  Printer(FILE *_fp) : fp(_fp) {}
  ~Printer() { flush(); }

  static constexpr size_t SIZE = 1 << 15;
  FILE *fp;
  char line[SIZE], small[50];
  size_t pos = 0;
  void flush() {
    fwrite(line, 1, pos, fp);
    pos = 0;
  }
  void write(const char val) {
    if (pos == SIZE) flush();
    line[pos++] = val;
  }
  template <class T, enable_if_t<is_integral<T>::value, int> = 0>
  void write(T val) {
    if (pos > (1 << 15) - 50) flush();
    if (val == 0) {
      write('0');
      return;
    }
    if (val < 0) {
      write('-');
      val = -val; // todo min
    }
    size_t len = 0;
    while (val) {
      small[len++] = char(0x30 | (val % 10));
      val /= 10;
    }
    for (size_t i = 0; i < len; i++) { line[pos + i] = small[len - 1 - i]; }
    pos += len;
  }
  void write(const string s) {
    for (char c: s) write(c);
  }
  void write(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++) write(s[i]);
  }
  void write(const double x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << x;
    string s = oss.str();
    write(s);
  }
  void write(const long double x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << x;
    string s = oss.str();
    write(s);
  }
  template <typename T,
            typename enable_if<has_write<T>::value>::type * = nullptr>
  inline void write(T x) {
    x.write();
  }
  template <class T>
  void write(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
      if (i) write(' ');
      write(val[i]);
    }
  }
  template <class T, class U>
  void write(const pair<T, U> val) {
    write(val.first);
    write(' ');
    write(val.second);
  }
  template <size_t N = 0, typename T>
  void write_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
      if constexpr (N > 0) { write(' '); }
      const auto x = std::get<N>(t);
      write(x);
      write_tuple<N + 1>(t);
    }
  }
  template <class... T>
  bool write(tuple<T...> tpl) {
    write_tuple(tpl);
    return true;
  }
  template <class T, size_t S>
  void write(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
      if (i) write(' ');
      write(val[i]);
    }
  }
  void write(i128 val) {
    string s;
    bool negative = 0;
    if (val < 0) {
      negative = 1;
      val = -val;
    }
    while (val) {
      s += '0' + int(val % 10);
      val /= 10;
    }
    if (negative) s += "-";
    reverse(all(s));
    if (len(s) == 0) s = "0";
    write(s);
  }
};
Scanner scanner = Scanner(stdin);
Printer printer = Printer(stdout);
void flush() { printer.flush(); }
void print() { printer.write('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  printer.write(head);
  if (sizeof...(Tail)) printer.write(' ');
  print(forward<Tail>(tail)...);
}

void read() {}
template <class Head, class... Tail>
void read(Head &head, Tail &... tail) {
  scanner.read(head);
  read(tail...);
}
} // namespace fastio
using fastio::print;
using fastio::flush;
using fastio::read;

#define INT(...)   \
  int __VA_ARGS__; \
  read(__VA_ARGS__)
#define LL(...)   \
  ll __VA_ARGS__; \
  read(__VA_ARGS__)
#define STR(...)      \
  string __VA_ARGS__; \
  read(__VA_ARGS__)
#define CHAR(...)   \
  char __VA_ARGS__; \
  read(__VA_ARGS__)
#define DBL(...)      \
  double __VA_ARGS__; \
  read(__VA_ARGS__)

#define VEC(type, name, size) \
  vector<type> name(size);    \
  read(name)
#define VV(type, name, h, w)                     \
  vector<vector<type>> name(h, vector<type>(w)); \
  read(name)

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 3 "main.cpp"

void solve() {
  LL(N, K, M, a, b);
  if (N % M == 0) return print(0);
  if (K == 1) { return print(-1); }

  auto solve = [&](i128 n) -> ll {
    i128 lo = n, hi = n;
    ll cnt = 0;
    while (1) {
      if (floor(hi, M) > floor(lo - 1, M)) { return cnt; }
      lo = K * lo;
      hi = K * hi + (K - 1);
      ++cnt;
    }
    assert(0);
    return 0;
  };

  ll ANS = infty<ll>;

  FOR(x, 100) {
    ll cost = b * x + a * solve(N);
    N /= K;
    chmin(ANS, cost);
  }
  print(ANS);
}

signed main() {
  INT(T);
  FOR(T) solve();
  return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3604kb

input:

4
101 4 207 3 5
8 3 16 100 1
114 514 19 19 810
1 1 3 1 1

output:

11
2
0
-1

result:

ok 4 number(s): "11 2 0 -1"

Test #2:

score: 0
Accepted
time: 148ms
memory: 3656kb

input:

100000
9 5 7 7674 78731
4 3 4 58482 93736
1 4 3 42396 22960
6 2 2 4534 73466
5 7 7 56203 19376
1 7 10 77129 84094
8 3 3 72793 89258
10 10 3 94847 42455
7 4 7 79273 90760
2 7 3 78496 99140
4 4 9 47018 14651
3 7 8 60936 4453
8 6 4 57267 6293
8 7 3 81697 99664
2 10 10 3935 30951
8 9 7 91391 70670
5 8 8...

output:

7674
0
22960
0
19376
77129
72793
84910
0
78496
29302
4453
0
81697
3935
70670
36522
21244
0
0
0
100934
30063
0
57852
31894
72016
6193
9486
2516
27536
0
7306
73625
11302
13802
41343
50014
58015
38743
65165
38963
26747
0
42044
45733
63574
69321
34196
1674
27200
8130
0
46609
53621
11696
7808
4630
10051
...

result:

ok 100000 numbers

Test #3:

score: 0
Accepted
time: 176ms
memory: 3644kb

input:

100000
72 56 61 725468539 908406897
78 7 86 485275009 977836982
25 57 29 104624183 334780226
48 74 44 805881518 26082346
87 26 31 224468594 59732782
55 29 99 697738785 876206855
96 85 8 998474252 490312988
11 22 7 298977007 759215221
43 72 22 785798936 836075792
16 16 29 304049814 445858780
86 24 36...

output:

725468539
970550018
104624183
26082346
119465564
1395477570
0
298977007
785798936
304049814
488620044
1112696878
150581202
929490259
258912618
156420265
767475208
623063452
158730933
211070701
576023224
525233
66950902
893398127
1538977472
552877592
365438928
274813702
347240596
413914126
411352478
...

result:

ok 100000 numbers

Test #4:

score: 0
Accepted
time: 177ms
memory: 3736kb

input:

100000
151 859 413 113296245 501509373
721 797 951 199093180 857704079
864 743 424 944343390 211412511
537 561 510 160063507 371248812
67 101 1000 982073931 983924207
224 620 106 988167382 31695532
388 496 373 179680114 906477657
463 865 318 568083479 906936536
409 549 816 183391318 716459594
871 83...

output:

113296245
199093180
422825022
160063507
983924207
31695532
179680114
568083479
366782636
353991726
424999871
270298556
845830412
171200301
342928747
708513732
1071693358
495915588
91647563
423066800
629029877
532122044
903837970
923069546
30892184
342614734
344281675
92814148
8303547
371747405
58158...

result:

ok 100000 numbers

Test #5:

score: 0
Accepted
time: 182ms
memory: 3576kb

input:

100000
4630 2977 9157 920976948 319551315
2827 5918 444 915741308 428850012
1830 2194 1995 883906440 695946422
3495 431 7000 831459352 331879489
6334 6866 3180 554770772 999524518
4394 865 2622 462975016 317225012
7146 2059 5206 338704464 650075526
7269 9699 7065 508253316 136145466
3717 9832 5501 1...

output:

639102630
428850012
695946422
663758978
554770772
634450024
677408928
136145466
138804545
86246388
654932853
233406504
158977692
141890698
149668965
289533426
536659273
578882913
234405244
160427375
155168698
546646968
5900866
186185047
30363396
93724506
330946208
71156738
151777321
386435297
166234...

result:

ok 100000 numbers

Test #6:

score: 0
Accepted
time: 183ms
memory: 3888kb

input:

100000
73249682 47619910 55116647 128554518 478392703
63789277 1414550 48229272 250747189 997808121
68243990 71103259 14595028 337838604 410310513
43474969 8461967 37722317 943841593 58972601
79052007 22427901 46110814 619079500 877950428
36298374 69387929 88793453 605131681 357216829
87609669 84382...

output:

257109036
501494378
337838604
117945202
1238159000
357216829
370639522
674316525
166433196
141880926
63179079
654049210
156730406
551517649
735314262
181349794
451156077
565079747
625657717
257899254
1205898584
736860320
436887048
555501015
634904039
720592503
12278164
173702793
193363767
979933288
...

result:

ok 100000 numbers

Test #7:

score: 0
Accepted
time: 186ms
memory: 3636kb

input:

100000
3464647282669819 76909462 18457991 390212875 487173929
4650003301142948 58807432 33266940 719515794 957413208
3623051027558998 54952606 51934480 131325868 905272434
2157584874927409 3499113 70686381 77518537 690462406
33017219084855 33767393 38574619 740268825 282227083
8188451643953574 58134...

output:

390212875
719515794
131325868
155037074
564454166
219227588
43753104
994443
502671816
299710451
565210982
474336918
433975652
48941841
496369573
863101565
245821709
440163633
726366897
267542384
562858097
952398862
586438103
210538560
124486961
766476932
676547307
983844074
853989168
375846543
31868...

result:

ok 100000 numbers

Test #8:

score: 0
Accepted
time: 165ms
memory: 3896kb

input:

100000
7275102973097459 8 5 378261522 402575783
4286374497798649 7 6 933502847 46810288
8023805803098978 8 9 35196391 195312588
4051746189241631 3 8 519770155 701983292
4216164515090411 7 9 182157078 199994837
6972811444444614 6 6 304516916 456411186
7951380680901262 9 2 961077532 951204780
47010508...

output:

378261522
140430864
35196391
1039540310
182157078
0
0
444998952
0
0
754484822
0
180947816
0
0
0
0
254006158
1780383378
218139523
785880599
738973224
462923534
0
0
957159359
713596284
0
0
336000605
734376280
367523046
950147662
742867914
367222451
0
470041638
524073733
217959245
303140703
1393714956
...

result:

ok 100000 numbers

Test #9:

score: 0
Accepted
time: 965ms
memory: 3732kb

input:

100000
3172946340513079 2 4329557 16791320 446472680
7579807106639385 2 5269014 874106039 38200115
8711378659665413 2 3851035 128312991 332862486
3140717354168532 2 1901428 309916408 293185488
7437587139203059 2 1175969 646142086 314686581
4409352538810139 2 4002447 651429755 612742609
6289991090148...

output:

369409040
2024606095
2822885802
5578495344
11630557548
12222416761
8115499634
8962597488
5498471198
11898230131
16491103671
4935576838
5308219664
14400043900
12414310000
7755940543
5590313290
12930920204
14957960241
1925773861
13204739592
7686770218
19623845780
7492468480
14957643942
3619976900
1059...

result:

ok 100000 numbers

Test #10:

score: 0
Accepted
time: 551ms
memory: 3632kb

input:

100000
8475355187425626 3 2406724 122893777 529073328
6285407806639448 3 3937413 294357884 733265747
6531289765480051 4 1050245 203974840 304729393
8485066096917699 4 3396909 592219121 695722382
7284155511893284 5 6754905 627447941 93546840
6777243058060513 4 3702369 411463540 526657758
235662177029...

output:

1720512878
4121010376
2039748400
5922191210
2151577320
4526098940
9057687050
22200571244
1939823860
9893222064
11149610680
3799751163
9292616296
7863963224
5813193048
6055859437
5210867229
4910282613
5060660555
7247199591
335238332
2940854800
11398266500
7787879580
978279903
6563104688
705652200
404...

result:

ok 100000 numbers

Test #11:

score: 0
Accepted
time: 228ms
memory: 3644kb

input:

100000
2 2 721468619 394072291 571875824
3 3 90264304 630955279 395985907
6 3 240084636 234840724 315419924
9 2 196662988 995651148 688364750
6 3 690293919 969307792 293007059
7 2 502948030 134974327 95527339
4 3 293565121 663233277 181484878
1 3 238930326 54563147 297523680
10 3 874489021 962296793...

output:

1143751648
791971814
630839848
2753459000
586014118
286582017
362969756
297523680
622079103
102876754
1562993362
1227171216
2007383385
530056636
1055467017
2488264744
437182876
83410242
788892006
586361822
638265729
2883645156
3067592872
3479355396
2794875222
2643697911
1520254412
2763055688
1684184...

result:

ok 100000 numbers