QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#102249#2551. Math String1234576AC ✓3ms3488kbC++144.2kb2023-05-02 17:57:142023-05-02 17:57:16

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-02 17:57:16]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3488kb
  • [2023-05-02 17:57:14]
  • 提交

answer

#include <map>
#include <set>
#include <array>
#include <cmath>
#include <queue>
#include <stack>
#include <tuple>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define db double
#define il inline
#define fir first
#define sec second
#define eps (1e-10)
#define pb push_back
#define ll long long
#define mkp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define lowbit(a) (a & (-a))
#define SZ(a) ((int)a.size())
#define ull unsigned long long
#define all(a) a.begin(), a.end()
#define split cout << "=========\n";
#define GG { cout << "NO\n"; return; }
#define pll pair<long long, long long>
#define equals(a, b) (fabs((a) - (b)) < eps)

constexpr int ON = 0;
constexpr int CW = -1;
constexpr int CCW = 1;
constexpr int BACK = 2;
constexpr int FRONT = -2;
const db pi = acos(-1.000);
constexpr int maxn = 5e5 + 50;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LINF =  0x3f3f3f3f3f3f3f3f;
constexpr int mod = 998244353; /* 1e9 + 7 */
constexpr int dir[8][2] = {-1, 0, -1, 1, 0, 1, 1, 1, 1, 0, 1, -1, 0, -1, -1, -1};



namespace Linear_seq {
#define N maxn
typedef long long LL;
LL mod = 998244353;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define pb push_back
typedef vector<int> VI;
typedef pair<int, int> PII;
// const int N = 10010;
LL res[N], base[N], _c[N], _md[N];
vector<int> Md;
LL powmod(LL a, LL b) {
  LL res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
void mul(LL *a, LL *b, int k) {
  rep(i, 0, k + k) _c[i] = 0;
  rep(i, 0, k) if (a[i]) rep(j, 0, k) _c[i + j] =
      (_c[i + j] + a[i] * b[j]) % mod;
  for (int i = k + k - 1; i >= k; i--)
    if (_c[i])
      rep(j, 0, SZ(Md)) _c[i - k + Md[j]] =
          (_c[i - k + Md[j]] - _c[i] * _md[Md[j]]) % mod;
  rep(i, 0, k) a[i] = _c[i];
}
int solve(LL n, VI a, VI b) {
  LL ans = 0, pnt = 0;
  int k = SZ(a);
  rep(i, 0, k) _md[k - 1 - i] = -a[i];
  _md[k] = 1;
  Md.clear();
  rep(i, 0, k) if (_md[i] != 0) Md.push_back(i);
  rep(i, 0, k) res[i] = base[i] = 0;
  res[0] = 1;
  while ((1LL << pnt) <= n)
    pnt++;
  for (int p = pnt; p >= 0; p--) {
    mul(res, res, k);
    if ((n >> p) & 1) {
      for (int i = k - 1; i >= 0; i--)
        res[i + 1] = res[i];
      res[0] = 0;
      rep(j, 0, SZ(Md)) res[Md[j]] = (res[Md[j]] - res[k] * _md[Md[j]]) % mod;
    }
  }
  rep(i, 0, k) ans = (ans + res[i] * b[i]) % mod;
  if (ans < 0)
    ans += mod;
  return ans;
}
VI BM(VI s) {
  VI C(1, 1), B(1, 1);
  int L = 0, m = 1, b = 1;
  rep(n, 0, SZ(s)) {
    LL d = 0;
    rep(i, 0, L + 1) d = (d + (LL)C[i] * s[n - i]) % mod;
    if (d == 0)
      ++m;
    else if (2 * L <= n) {
      VI T = C;
      LL c = mod - d * powmod(b, mod - 2) % mod;
      while (SZ(C) < SZ(B) + m)
        C.pb(0);
      rep(i, 0, SZ(B)) C[i + m] = (C[i + m] + c * B[i]) % mod;
      L = n + 1 - L;
      B = T;
      b = d;
      m = 1;
    } else {
      LL c = mod - d * powmod(b, mod - 2) % mod;
      while (SZ(C) < SZ(B) + m)
        C.pb(0);
      rep(i, 0, SZ(B)) C[i + m] = (C[i + m] + c * B[i]) % mod;
      ++m;
    }
  }
  return C;
}
int gao(VI a, LL n) {
  VI c = BM(a);
  c.erase(c.begin());
  rep(i, 0, SZ(c)) c[i] = (mod - c[i]) % mod;
  return solve(n, c, VI(a.begin(), a.begin() + SZ(c)));
}
}; // namespace Linear_seq

int n;
int ans;

void solve(int cas) {
    ll n; cin >> n;
    vector<int> a;
    a.pb(45);
    a.pb(4455);
    a.pb(407430);
    a.pb(36934785);
    a.pb(350210541);
    a.pb(427185456);
    a.pb(991901155);
    a.pb(110899952);
    a.pb(89411672);
    a.pb(401287887);
    a.pb(811189931);
    a.pb(286603985);
    a.pb(426843378);
    a.pb(418261776);
    a.pb(744223671);
    a.pb(302153364);
    a.pb(34240762);

// 689891595
// 101012015
// 748341487
    cout << Linear_seq::gao(a, n - 1);
}




signed main() {
    // cout << fixed << setprecision(10);
    ios::sync_with_stdio(false); cin.tie(nullptr);
    // int T; cin>>T; while (T--)
    solve(1);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3376kb

input:

1

output:

45

result:

ok answer is '45'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3336kb

input:

3

output:

407430

result:

ok answer is '407430'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3328kb

input:

1000000000000000000

output:

493565653

result:

ok answer is '493565653'

Test #4:

score: 0
Accepted
time: 2ms
memory: 3396kb

input:

999999999999999254

output:

963821656

result:

ok answer is '963821656'

Test #5:

score: 0
Accepted
time: 2ms
memory: 3336kb

input:

2

output:

4455

result:

ok answer is '4455'

Test #6:

score: 0
Accepted
time: 2ms
memory: 3464kb

input:

999999999999999062

output:

256461144

result:

ok answer is '256461144'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3484kb

input:

4

output:

36934785

result:

ok answer is '36934785'

Test #8:

score: 0
Accepted
time: 3ms
memory: 3464kb

input:

5

output:

350210541

result:

ok answer is '350210541'

Test #9:

score: 0
Accepted
time: 2ms
memory: 3484kb

input:

6

output:

427185456

result:

ok answer is '427185456'

Test #10:

score: 0
Accepted
time: 2ms
memory: 3344kb

input:

7

output:

991901155

result:

ok answer is '991901155'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3412kb

input:

8

output:

110899952

result:

ok answer is '110899952'

Test #12:

score: 0
Accepted
time: 1ms
memory: 3336kb

input:

9

output:

89411672

result:

ok answer is '89411672'

Test #13:

score: 0
Accepted
time: 2ms
memory: 3444kb

input:

10

output:

401287887

result:

ok answer is '401287887'

Test #14:

score: 0
Accepted
time: 2ms
memory: 3420kb

input:

172

output:

376377812

result:

ok answer is '376377812'

Test #15:

score: 0
Accepted
time: 3ms
memory: 3432kb

input:

238

output:

81946973

result:

ok answer is '81946973'

Test #16:

score: 0
Accepted
time: 2ms
memory: 3336kb

input:

730

output:

661959857

result:

ok answer is '661959857'

Test #17:

score: 0
Accepted
time: 2ms
memory: 3484kb

input:

684

output:

828317367

result:

ok answer is '828317367'

Test #18:

score: 0
Accepted
time: 1ms
memory: 3468kb

input:

633

output:

673539741

result:

ok answer is '673539741'

Test #19:

score: 0
Accepted
time: 2ms
memory: 3444kb

input:

897

output:

159321465

result:

ok answer is '159321465'

Test #20:

score: 0
Accepted
time: 1ms
memory: 3412kb

input:

809

output:

521464595

result:

ok answer is '521464595'

Test #21:

score: 0
Accepted
time: 0ms
memory: 3464kb

input:

302

output:

92391482

result:

ok answer is '92391482'

Test #22:

score: 0
Accepted
time: 0ms
memory: 3412kb

input:

261

output:

854903269

result:

ok answer is '854903269'

Test #23:

score: 0
Accepted
time: 1ms
memory: 3484kb

input:

497

output:

594207939

result:

ok answer is '594207939'

Test #24:

score: 0
Accepted
time: 2ms
memory: 3416kb

input:

951

output:

927809758

result:

ok answer is '927809758'

Test #25:

score: 0
Accepted
time: 1ms
memory: 3396kb

input:

980

output:

65372821

result:

ok answer is '65372821'

Test #26:

score: 0
Accepted
time: 2ms
memory: 3464kb

input:

1000

output:

971150090

result:

ok answer is '971150090'

Test #27:

score: 0
Accepted
time: 1ms
memory: 3372kb

input:

969

output:

511011493

result:

ok answer is '511011493'

Test #28:

score: 0
Accepted
time: 2ms
memory: 3336kb

input:

998

output:

549357456

result:

ok answer is '549357456'

Test #29:

score: 0
Accepted
time: 1ms
memory: 3416kb

input:

98558

output:

245733611

result:

ok answer is '245733611'

Test #30:

score: 0
Accepted
time: 2ms
memory: 3488kb

input:

35873

output:

524107440

result:

ok answer is '524107440'

Test #31:

score: 0
Accepted
time: 1ms
memory: 3364kb

input:

3015

output:

928761172

result:

ok answer is '928761172'

Test #32:

score: 0
Accepted
time: 2ms
memory: 3392kb

input:

44398

output:

339084928

result:

ok answer is '339084928'

Test #33:

score: 0
Accepted
time: 0ms
memory: 3328kb

input:

82497

output:

273305194

result:

ok answer is '273305194'

Test #34:

score: 0
Accepted
time: 2ms
memory: 3344kb

input:

81678

output:

423439974

result:

ok answer is '423439974'

Test #35:

score: 0
Accepted
time: 2ms
memory: 3328kb

input:

95002

output:

868411966

result:

ok answer is '868411966'

Test #36:

score: 0
Accepted
time: 2ms
memory: 3404kb

input:

56392

output:

127537737

result:

ok answer is '127537737'

Test #37:

score: 0
Accepted
time: 1ms
memory: 3368kb

input:

49489

output:

841113901

result:

ok answer is '841113901'

Test #38:

score: 0
Accepted
time: 2ms
memory: 3412kb

input:

57109

output:

808819191

result:

ok answer is '808819191'

Test #39:

score: 0
Accepted
time: 2ms
memory: 3444kb

input:

99674

output:

890052301

result:

ok answer is '890052301'

Test #40:

score: 0
Accepted
time: 2ms
memory: 3336kb

input:

99513

output:

147223708

result:

ok answer is '147223708'

Test #41:

score: 0
Accepted
time: 2ms
memory: 3460kb

input:

99950

output:

638000302

result:

ok answer is '638000302'

Test #42:

score: 0
Accepted
time: 2ms
memory: 3464kb

input:

99939

output:

627100241

result:

ok answer is '627100241'

Test #43:

score: 0
Accepted
time: 0ms
memory: 3460kb

input:

99904

output:

768803875

result:

ok answer is '768803875'

Test #44:

score: 0
Accepted
time: 2ms
memory: 3332kb

input:

822981260158560519

output:

500129705

result:

ok answer is '500129705'

Test #45:

score: 0
Accepted
time: 2ms
memory: 3332kb

input:

28316250878314571

output:

954707612

result:

ok answer is '954707612'

Test #46:

score: 0
Accepted
time: 1ms
memory: 3376kb

input:

779547116602636424

output:

349022088

result:

ok answer is '349022088'

Test #47:

score: 0
Accepted
time: 2ms
memory: 3336kb

input:

578223540025879436

output:

310507001

result:

ok answer is '310507001'

Test #48:

score: 0
Accepted
time: 2ms
memory: 3464kb

input:

335408917862248766

output:

399860005

result:

ok answer is '399860005'

Test #49:

score: 0
Accepted
time: 2ms
memory: 3336kb

input:

74859962623990078

output:

905924996

result:

ok answer is '905924996'

Test #50:

score: 0
Accepted
time: 2ms
memory: 3412kb

input:

252509054434733439

output:

57677315

result:

ok answer is '57677315'

Test #51:

score: 0
Accepted
time: 2ms
memory: 3364kb

input:

760713016476890622

output:

840620988

result:

ok answer is '840620988'

Test #52:

score: 0
Accepted
time: 2ms
memory: 3340kb

input:

919845426262803496

output:

929606336

result:

ok answer is '929606336'

Test #53:

score: 0
Accepted
time: 2ms
memory: 3304kb

input:

585335723211847194

output:

975973040

result:

ok answer is '975973040'

Test #54:

score: 0
Accepted
time: 2ms
memory: 3412kb

input:

999999999999999478

output:

859690282

result:

ok answer is '859690282'

Test #55:

score: 0
Accepted
time: 2ms
memory: 3412kb

input:

999999999999999902

output:

879587490

result:

ok answer is '879587490'

Test #56:

score: 0
Accepted
time: 3ms
memory: 3428kb

input:

999999999999999168

output:

585232180

result:

ok answer is '585232180'