QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#106277#2074. LCM SumScintillaAC ✓6893ms414356kbC++144.9kb2023-05-17 08:45:432023-05-17 08:45:45

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-17 08:45:45]
  • 评测
  • 测评结果:AC
  • 用时:6893ms
  • 内存:414356kb
  • [2023-05-17 08:45:43]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define drep(i, s, e) for (int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define pv(a) cout << #a << " = " << a << endl
#define pa(a, l, r) cout << #a " : "; rep(_, l, r) cout << a[_] << ' '; cout << endl

using ll = long long;

const ll L = 2329089562800ll;

const int P = 1e9 + 7;

const int N = 30 + 5;
const int M = 3e6 + 10;

const int L1 = 831600;
const int L2 = 2800733;

const ll M1 = 2151514688401ll;
const ll M2 = 177574874400ll;

const int prime[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 };
const int factor[] = { 16, 27, 25, 7, 11, 13, 17, 19, 23, 29 };

ll read() {
  ll x = 0, f = 1; char c = getchar();
  for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
  return x * f;
}

int inc(int a, int b) { return (a += b) >= P ? a - P : a; }
int dec(int a, int b) { return (a -= b) < 0 ? a + P : a; }
int mul(int a, int b) { return 1ll * a * b % P; }
void add(int &a, int b) { (a += b) >= P ? a -= P : 1; }
void sub(int &a, int b) { (a -= b) < 0 ? a += P : 1; }
int sgn(int x) { return x & 1 ? P - 1 : 1; }
int qpow(int a, int b) { int res = 1; for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a); return res; }

int fac[N], inv[N], finv[N];
void init(int w) {
  fac[0] = inv[1] = finv[0] = 1;
  rep(i, 1, w) fac[i] = mul(fac[i - 1], i);
  rep(i, 2, w) inv[i] = P - mul(P / i, inv[P % i]);
  rep(i, 1, w) finv[i] = mul(finv[i - 1], inv[i]);
}

int C(int a, int b) {
  if (a < b || b < 0) return 0;
  return mul(fac[a], mul(finv[b], finv[a - b]));
}

ll gcd(ll a, ll b) {
  return __gcd(a, b);
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

struct lagrange {
  int len, y[N], pre[N], suf[N];
  int calc(ll x) {
    if (x <= len) return y[x];
    pre[0] = suf[len + 1] = 1;
    rep(i, 1, len) pre[i] = mul(pre[i - 1], (x - i) % P);
    drep(i, len, 1) suf[i] = mul(suf[i + 1], (x - i) % P);
    int res = 0;
    rep(i, 1, len) {
      int t = mul(pre[i - 1], suf[i + 1]);
      t = mul(mul(t, sgn(len - i)), mul(finv[i - 1], finv[len - i]));
      add(res, mul(y[i], t));
    }
    return res;
  }
} lag[N];

long long n, w;
int m, ans;

int coef[N], f[N][N], g[N][N], cf[N][N], cg[N][N], pw[N], c[N][N];

int pre[N][M];
pair <ll, int> r1[M], r2[M];

void prework() {
  rep(i, 0, 31) {
    lag[i].len = i + 2, lag[i].y[0] = !i;
    rep(j, 1, i + 2) {
      lag[i].y[j] = inc(lag[i].y[j - 1], qpow(j, i));
    }
  }
  w = (n - 1) / L;
  rep(i, 0, m) pw[i] = lag[i].calc(w);
  coef[0] = 1;
  rep(i, 0, m - 1) drep(j, i, 0) {
    add(coef[j + 1], coef[j]);
    coef[j] = mul(coef[j], i);
  }
  rep(a, 0, m) rep(b, 0, m) rep(c, 0, m) {
    if (a + b + c > m) break;
    int t = mul(coef[a + b + c], fac[a + b + c]);
    t = mul(mul(t, finv[a]), mul(finv[b], finv[c]));
    add(f[b][c], mul(t, mul(pw[a], qpow(L % P, a))));
    add(g[b][c], mul(t, qpow(mul(w % P, L % P), a)));
  }
  auto vp = [&](int x, int p) {
    int res = 0;
    while (!(x % p)) ++ res, x /= p;
    return res;
  } ;
  rep(i, 0, 9) rep(j, 1, factor[i]) {
    int sum = 0, mx = 0;
    rep(k, 0, m - 1) {
      sum += vp(j + k, prime[i]);
      mx = max(mx, vp(j + k, prime[i]));
    }
    c[i][j % factor[i]] = qpow(prime[i], sum - mx);
  }
  rep(i, 0, L1 - 1) {
    ll u = i * M1 % L;
    int v = 1;
    rep(j, 0, 4) v = mul(v, c[j][i % factor[j]]);
    r1[i] = make_pair(u, v);
  }
  rep(i, 0, L2 - 1) {
    ll u = i * M2 % L;
    int v = 1;
    rep(j, 5, 9) v = mul(v, c[j][i % factor[j]]);
    r2[i] = make_pair(u, v);
  }
  sort(r1, r1 + L1);
  sort(r2, r2 + L2);
  rep(i, 1, L2) {
    for (int j = 0, x = qpow(r2[i - 1].second, P - 2); j <= m; ++ j)  {
      pre[j][i] = inc(pre[j][i - 1], x);
      x = mul(x, r2[i - 1].first % P);
    }
  }
}

int main() {
  init(N - 1);
  n = read(), m = read() + 1;
  prework();
  for (int i = L1 - 1, j1 = 0, j2 = 0, j3 = 0; ~i; -- i) {
    while (j1 < L2 && r1[i].first + r2[j1].first < L && w * L + r1[i].first + r2[j1].first <= n) ++ j1;
    while (j2 < L2 && r1[i].first + r2[j2].first < L) ++ j2;
    j3 = max(j3, j2);
    while (j3 < L2 && w * L + r1[i].first + r2[j3].first - L <= n) ++ j3;
    for (int u = 0, x = qpow(r1[i].second, P - 2), y = x; u <= m; ++ u) {
      rep(v, 0, m - u) {
        auto ask = [&](int l, int r) { return dec(pre[v][r], pre[v][l]); } ;
        add(cf[u][v], inc(mul(x, ask(0, j2)), mul(y, ask(j2, L2))));
        add(cg[u][v], inc(mul(x, ask(j1, j2)), mul(y, ask(j3, L2))));
      }
      x = mul(x, r1[i].first % P);
      y = mul(y, ((r1[i].first - L) % P + P) % P);
    }
  }
  rep(u, 0, m) rep(v, 0, m) {
    add(ans, mul(f[u][v], cf[u][v]));
    sub(ans, mul(g[u][v], cg[u][v]));
  }
  printf("%d\n", ans);
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1064ms
memory: 115552kb

input:

10 3

output:

18936

result:

ok single line: '18936'

Test #2:

score: 0
Accepted
time: 1224ms
memory: 149132kb

input:

10000 6

output:

43482752

result:

ok single line: '43482752'

Test #3:

score: 0
Accepted
time: 2361ms
memory: 247808kb

input:

1000000000 15

output:

688102997

result:

ok single line: '688102997'

Test #4:

score: 0
Accepted
time: 6879ms
memory: 412184kb

input:

1000000000000000000 30

output:

524223287

result:

ok single line: '524223287'

Test #5:

score: 0
Accepted
time: 947ms
memory: 94748kb

input:

1000000000000000000 1

output:

41650

result:

ok single line: '41650'

Test #6:

score: 0
Accepted
time: 997ms
memory: 107840kb

input:

1000000000000000000 2

output:

688702180

result:

ok single line: '688702180'

Test #7:

score: 0
Accepted
time: 1052ms
memory: 116360kb

input:

1000000000000000000 3

output:

26803356

result:

ok single line: '26803356'

Test #8:

score: 0
Accepted
time: 1106ms
memory: 127248kb

input:

1000000000000000000 4

output:

318915933

result:

ok single line: '318915933'

Test #9:

score: 0
Accepted
time: 1201ms
memory: 138584kb

input:

1000000000000000000 5

output:

355484656

result:

ok single line: '355484656'

Test #10:

score: 0
Accepted
time: 1270ms
memory: 149424kb

input:

1000000000000000000 6

output:

162499027

result:

ok single line: '162499027'

Test #11:

score: 0
Accepted
time: 1339ms
memory: 160452kb

input:

1000000000000000000 7

output:

60587090

result:

ok single line: '60587090'

Test #12:

score: 0
Accepted
time: 1453ms
memory: 171008kb

input:

1000000000000000000 8

output:

47433228

result:

ok single line: '47433228'

Test #13:

score: 0
Accepted
time: 1523ms
memory: 182096kb

input:

1000000000000000000 9

output:

52651033

result:

ok single line: '52651033'

Test #14:

score: 0
Accepted
time: 1644ms
memory: 193208kb

input:

1000000000000000000 10

output:

488431192

result:

ok single line: '488431192'

Test #15:

score: 0
Accepted
time: 2028ms
memory: 203848kb

input:

1000000000000000000 11

output:

203359516

result:

ok single line: '203359516'

Test #16:

score: 0
Accepted
time: 2234ms
memory: 217272kb

input:

1000000000000000000 12

output:

676816954

result:

ok single line: '676816954'

Test #17:

score: 0
Accepted
time: 2371ms
memory: 225252kb

input:

1000000000000000000 13

output:

792261385

result:

ok single line: '792261385'

Test #18:

score: 0
Accepted
time: 2535ms
memory: 237292kb

input:

1000000000000000000 14

output:

266241285

result:

ok single line: '266241285'

Test #19:

score: 0
Accepted
time: 2767ms
memory: 246760kb

input:

1000000000000000000 15

output:

779954568

result:

ok single line: '779954568'

Test #20:

score: 0
Accepted
time: 2992ms
memory: 257960kb

input:

1000000000000000000 16

output:

661462563

result:

ok single line: '661462563'

Test #21:

score: 0
Accepted
time: 3224ms
memory: 269692kb

input:

1000000000000000000 17

output:

157882037

result:

ok single line: '157882037'

Test #22:

score: 0
Accepted
time: 3358ms
memory: 280592kb

input:

1000000000000000000 18

output:

707666921

result:

ok single line: '707666921'

Test #23:

score: 0
Accepted
time: 3565ms
memory: 291632kb

input:

1000000000000000000 19

output:

75350354

result:

ok single line: '75350354'

Test #24:

score: 0
Accepted
time: 3830ms
memory: 302360kb

input:

1000000000000000000 20

output:

190809078

result:

ok single line: '190809078'

Test #25:

score: 0
Accepted
time: 4108ms
memory: 313476kb

input:

1000000000000000000 21

output:

485802406

result:

ok single line: '485802406'

Test #26:

score: 0
Accepted
time: 4332ms
memory: 324544kb

input:

1000000000000000000 22

output:

518652177

result:

ok single line: '518652177'

Test #27:

score: 0
Accepted
time: 4642ms
memory: 335220kb

input:

1000000000000000000 23

output:

172946983

result:

ok single line: '172946983'

Test #28:

score: 0
Accepted
time: 4915ms
memory: 346308kb

input:

1000000000000000000 24

output:

342420888

result:

ok single line: '342420888'

Test #29:

score: 0
Accepted
time: 5254ms
memory: 357296kb

input:

1000000000000000000 25

output:

497552775

result:

ok single line: '497552775'

Test #30:

score: 0
Accepted
time: 5481ms
memory: 368148kb

input:

1000000000000000000 26

output:

920161969

result:

ok single line: '920161969'

Test #31:

score: 0
Accepted
time: 5783ms
memory: 379260kb

input:

1000000000000000000 27

output:

131607220

result:

ok single line: '131607220'

Test #32:

score: 0
Accepted
time: 6155ms
memory: 389928kb

input:

1000000000000000000 28

output:

551838958

result:

ok single line: '551838958'

Test #33:

score: 0
Accepted
time: 6468ms
memory: 400844kb

input:

1000000000000000000 29

output:

851846988

result:

ok single line: '851846988'

Test #34:

score: 0
Accepted
time: 924ms
memory: 83588kb

input:

1000000000000000000 0

output:

1225

result:

ok single line: '1225'

Test #35:

score: 0
Accepted
time: 923ms
memory: 83524kb

input:

265714758284843011 0

output:

708589

result:

ok single line: '708589'

Test #36:

score: 0
Accepted
time: 961ms
memory: 96628kb

input:

266540997167959139 1

output:

881831692

result:

ok single line: '881831692'

Test #37:

score: 0
Accepted
time: 987ms
memory: 105384kb

input:

267367244641009859 2

output:

423211036

result:

ok single line: '423211036'

Test #38:

score: 0
Accepted
time: 1038ms
memory: 116428kb

input:

268193483524125987 3

output:

127124157

result:

ok single line: '127124157'

Test #39:

score: 0
Accepted
time: 1109ms
memory: 127464kb

input:

269019726702209411 4

output:

39777520

result:

ok single line: '39777520'

Test #40:

score: 0
Accepted
time: 1180ms
memory: 138316kb

input:

269845965585325539 5

output:

577495858

result:

ok single line: '577495858'

Test #41:

score: 0
Accepted
time: 1279ms
memory: 149168kb

input:

270672213058376259 6

output:

262428469

result:

ok single line: '262428469'

Test #42:

score: 0
Accepted
time: 1342ms
memory: 160092kb

input:

271498451941492387 7

output:

878988911

result:

ok single line: '878988911'

Test #43:

score: 0
Accepted
time: 1454ms
memory: 171316kb

input:

272324690824608515 8

output:

844720221

result:

ok single line: '844720221'

Test #44:

score: 0
Accepted
time: 1572ms
memory: 182032kb

input:

273150934002691939 9

output:

20339607

result:

ok single line: '20339607'

Test #45:

score: 0
Accepted
time: 1745ms
memory: 193184kb

input:

996517375802030518 10

output:

436000085

result:

ok single line: '436000085'

Test #46:

score: 0
Accepted
time: 1953ms
memory: 203868kb

input:

997343614685146646 11

output:

172229324

result:

ok single line: '172229324'

Test #47:

score: 0
Accepted
time: 2150ms
memory: 217072kb

input:

998169857863230070 12

output:

297495611

result:

ok single line: '297495611'

Test #48:

score: 0
Accepted
time: 2378ms
memory: 225748kb

input:

998996101041313494 13

output:

516501983

result:

ok single line: '516501983'

Test #49:

score: 0
Accepted
time: 2518ms
memory: 236940kb

input:

999822344219396918 14

output:

917263884

result:

ok single line: '917263884'

Test #50:

score: 0
Accepted
time: 2728ms
memory: 247916kb

input:

648583102513046 15

output:

962851231

result:

ok single line: '962851231'

Test #51:

score: 0
Accepted
time: 2939ms
memory: 258756kb

input:

1474821985629174 16

output:

635473880

result:

ok single line: '635473880'

Test #52:

score: 0
Accepted
time: 3133ms
memory: 270228kb

input:

2301069458679894 17

output:

686837493

result:

ok single line: '686837493'

Test #53:

score: 0
Accepted
time: 3418ms
memory: 281156kb

input:

3127308341796022 18

output:

746101270

result:

ok single line: '746101270'

Test #54:

score: 0
Accepted
time: 3550ms
memory: 291484kb

input:

3953551519879446 19

output:

517293260

result:

ok single line: '517293260'

Test #55:

score: 0
Accepted
time: 3864ms
memory: 302532kb

input:

738505179452405440 20

output:

96504747

result:

ok single line: '96504747'

Test #56:

score: 0
Accepted
time: 4011ms
memory: 313476kb

input:

739331418335521569 21

output:

151678490

result:

ok single line: '151678490'

Test #57:

score: 0
Accepted
time: 4284ms
memory: 326324kb

input:

740157665808572289 22

output:

548846725

result:

ok single line: '548846725'

Test #58:

score: 0
Accepted
time: 4630ms
memory: 335264kb

input:

740983904691688417 23

output:

260809011

result:

ok single line: '260809011'

Test #59:

score: 0
Accepted
time: 4866ms
memory: 346308kb

input:

741810147869771841 24

output:

62064725

result:

ok single line: '62064725'

Test #60:

score: 0
Accepted
time: 5192ms
memory: 357348kb

input:

742636386752887969 25

output:

378996555

result:

ok single line: '378996555'

Test #61:

score: 0
Accepted
time: 5374ms
memory: 368716kb

input:

743462629930971393 26

output:

749268774

result:

ok single line: '749268774'

Test #62:

score: 0
Accepted
time: 5842ms
memory: 379212kb

input:

744288873109054817 27

output:

343279726

result:

ok single line: '343279726'

Test #63:

score: 0
Accepted
time: 6037ms
memory: 390620kb

input:

745115111992170945 28

output:

275401202

result:

ok single line: '275401202'

Test #64:

score: 0
Accepted
time: 6421ms
memory: 401324kb

input:

745941355170254369 29

output:

482258407

result:

ok single line: '482258407'

Test #65:

score: 0
Accepted
time: 6792ms
memory: 411804kb

input:

257120946248004555 30

output:

871039750

result:

ok single line: '871039750'

Test #66:

score: 0
Accepted
time: 1211ms
memory: 138256kb

input:

96 5

output:

821858903

result:

ok single line: '821858903'

Test #67:

score: 0
Accepted
time: 2952ms
memory: 291412kb

input:

52 19

output:

457717981

result:

ok single line: '457717981'

Test #68:

score: 0
Accepted
time: 1627ms
memory: 193504kb

input:

96 10

output:

169742074

result:

ok single line: '169742074'

Test #69:

score: 0
Accepted
time: 4139ms
memory: 346240kb

input:

37 24

output:

999563342

result:

ok single line: '999563342'

Test #70:

score: 0
Accepted
time: 1730ms
memory: 204152kb

input:

81 11

output:

38929854

result:

ok single line: '38929854'

Test #71:

score: 0
Accepted
time: 4506ms
memory: 357492kb

input:

21 25

output:

664668034

result:

ok single line: '664668034'

Test #72:

score: 0
Accepted
time: 2421ms
memory: 258708kb

input:

70 16

output:

725245983

result:

ok single line: '725245983'

Test #73:

score: 0
Accepted
time: 6313ms
memory: 412044kb

input:

22 30

output:

167544969

result:

ok single line: '167544969'

Test #74:

score: 0
Accepted
time: 2048ms
memory: 225780kb

input:

63 13

output:

743502454

result:

ok single line: '743502454'

Test #75:

score: 0
Accepted
time: 906ms
memory: 83876kb

input:

7 0

output:

28

result:

ok single line: '28'

Test #76:

score: 0
Accepted
time: 6893ms
memory: 412784kb

input:

267367244641009859 30

output:

625470986

result:

ok single line: '625470986'

Test #77:

score: 0
Accepted
time: 6648ms
memory: 411972kb

input:

268193483524125987 30

output:

55213829

result:

ok single line: '55213829'

Test #78:

score: 0
Accepted
time: 6738ms
memory: 411928kb

input:

269019726702209411 30

output:

965929889

result:

ok single line: '965929889'

Test #79:

score: 0
Accepted
time: 6752ms
memory: 411928kb

input:

269845965585325539 30

output:

87993358

result:

ok single line: '87993358'

Test #80:

score: 0
Accepted
time: 6771ms
memory: 412316kb

input:

270672213058376259 30

output:

88337416

result:

ok single line: '88337416'

Test #81:

score: 0
Accepted
time: 6651ms
memory: 412200kb

input:

271498451941492387 30

output:

753017833

result:

ok single line: '753017833'

Test #82:

score: 0
Accepted
time: 6832ms
memory: 411860kb

input:

272324690824608515 30

output:

972883027

result:

ok single line: '972883027'

Test #83:

score: 0
Accepted
time: 6731ms
memory: 412556kb

input:

273150934002691939 30

output:

644302994

result:

ok single line: '644302994'

Test #84:

score: 0
Accepted
time: 892ms
memory: 83532kb

input:

1 0

output:

1

result:

ok single line: '1'

Test #85:

score: 0
Accepted
time: 945ms
memory: 95136kb

input:

1 1

output:

2

result:

ok single line: '2'

Test #86:

score: 0
Accepted
time: 6281ms
memory: 414356kb

input:

1 30

output:

775941393

result:

ok single line: '775941393'

Test #87:

score: 0
Accepted
time: 6295ms
memory: 412488kb

input:

100 30

output:

329365290

result:

ok single line: '329365290'