QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#562426#8184. Different Summands CountingAfterlife#AC ✓318ms11700kbC++202.0kb2024-09-13 17:30:232024-09-13 17:30:24

Judging History

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

  • [2024-09-13 17:30:24]
  • 评测
  • 测评结果:AC
  • 用时:318ms
  • 内存:11700kb
  • [2024-09-13 17:30:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
ll n;
int m ;
const int N = 1e6;
const int mod = 998244353;
int qpow(int a,int b) {
    int ans = 1;
    while(b) {
        if(b & 1) ans = 1LL * ans * a %mod;
        a = 1LL * a * a %mod; b >>= 1;
    }
    return ans;
}
int t[N + 5] , rt[N + 5];
int C(int a,int b) {
    if(a == -1 && b == -1) return 1;
    if(b < 0) return 0;
    if(a < 0) return 0;
    if(a < b) return 0;
    return 1LL * t[a] * rt[b] % mod * rt[a - b] % mod;
}
int g[505];
int inter(vector<int> v , int k) {
    int ans=0;
    int n=v.size()-1;
    for(int i=0;i<=n;++i){
        int A=1,B=1;
        for(int j=0;j<=n;++j){
            if(i==j)continue;
            A=1LL*A*(k-j)%mod;
            B=1LL*B*(i-j)%mod;
        }
        A=(A+mod)%mod;
        B=(B+mod)%mod;
        ans=(ans+1LL*A*qpow(B,mod-2)%mod*v[i])%mod;
    }
    return ans;
}
int calc(int a,int b,int d,ll r) {
    vector<int> v(d + 2) ;
    for(int i = 0;i <= d + 1;i++) {
        v[i] = 0;
        if(i) v[i] = v[i - 1];
        v[i] = (v[i] + C(a * i + b , d)) % mod;
    }
    int ans = inter(v , r % mod) ;
    return ans;
}
int main() {
    cin >> n >> m;
    t[0] = rt[0] = 1;
    for(int i = 1;i <= N;i++) t[i] = 1LL * t[i - 1] * i % mod , rt[i] = qpow(t[i] , mod - 2);
    int ans = 0;
    for(int i = 1;i <= m;i++) {
        g[i] = 0;
        // for(int k = 1 ; k <= n ; k++) {
        //     g[i] = (g[i] + C(n - i*k - 1 , m - i - 1)) % mod;
        //     // printf("true %d %d\n",n-i*k-1 , m - i - 1) ;
        // }
        if(i == m) {
            if(n % m == 0) g[i] = 1;
            else g[i] = 0;
        }
        else {
            g[i] = calc(i , (n - 1) % i , m - i - 1 , (n - 1) / i - 1) ;
        }
        g[i] = 1LL * g[i] * C(m , i) % mod;
        // printf("%d %d\n",i,g[i]) ;
        if(i & 1) ans= (ans + g[i]) % mod;
        else ans = (ans - g[i] + mod) % mod ;
    }
    cout << ans << '\n';
}

详细

Test #1:

score: 100
Accepted
time: 125ms
memory: 11404kb

input:

10 2

output:

17

result:

ok 1 number(s): "17"

Test #2:

score: 0
Accepted
time: 122ms
memory: 11340kb

input:

20 4

output:

3413

result:

ok 1 number(s): "3413"

Test #3:

score: 0
Accepted
time: 122ms
memory: 11640kb

input:

30 7

output:

2405830

result:

ok 1 number(s): "2405830"

Test #4:

score: 0
Accepted
time: 126ms
memory: 11428kb

input:

25 4

output:

7336

result:

ok 1 number(s): "7336"

Test #5:

score: 0
Accepted
time: 314ms
memory: 11700kb

input:

1000000000000000000 500

output:

423462987

result:

ok 1 number(s): "423462987"

Test #6:

score: 0
Accepted
time: 126ms
memory: 11328kb

input:

999999999999691765 1

output:

1

result:

ok 1 number(s): "1"

Test #7:

score: 0
Accepted
time: 126ms
memory: 11648kb

input:

999995937371566570 1

output:

1

result:

ok 1 number(s): "1"

Test #8:

score: 0
Accepted
time: 126ms
memory: 11428kb

input:

959 1

output:

1

result:

ok 1 number(s): "1"

Test #9:

score: 0
Accepted
time: 118ms
memory: 11604kb

input:

738 2

output:

1473

result:

ok 1 number(s): "1473"

Test #10:

score: 0
Accepted
time: 121ms
memory: 11368kb

input:

51940862 2

output:

103881721

result:

ok 1 number(s): "103881721"

Test #11:

score: 0
Accepted
time: 122ms
memory: 11408kb

input:

534 2

output:

1065

result:

ok 1 number(s): "1065"

Test #12:

score: 0
Accepted
time: 114ms
memory: 11608kb

input:

1000000000000000000 3

output:

845235930

result:

ok 1 number(s): "845235930"

Test #13:

score: 0
Accepted
time: 125ms
memory: 11424kb

input:

999999999999999999 3

output:

693511949

result:

ok 1 number(s): "693511949"

Test #14:

score: 0
Accepted
time: 126ms
memory: 11344kb

input:

864 3

output:

1114567

result:

ok 1 number(s): "1114567"

Test #15:

score: 0
Accepted
time: 126ms
memory: 11408kb

input:

591809296303238498 4

output:

293545419

result:

ok 1 number(s): "293545419"

Test #16:

score: 0
Accepted
time: 122ms
memory: 11412kb

input:

4979 5

output:

489533133

result:

ok 1 number(s): "489533133"

Test #17:

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

input:

999996551350045349 5

output:

94086466

result:

ok 1 number(s): "94086466"

Test #18:

score: 0
Accepted
time: 124ms
memory: 11420kb

input:

6016698794637 10

output:

21019269

result:

ok 1 number(s): "21019269"

Test #19:

score: 0
Accepted
time: 127ms
memory: 11340kb

input:

807 10

output:

926457609

result:

ok 1 number(s): "926457609"

Test #20:

score: 0
Accepted
time: 126ms
memory: 11392kb

input:

1000000000000000000 20

output:

942748867

result:

ok 1 number(s): "942748867"

Test #21:

score: 0
Accepted
time: 125ms
memory: 11320kb

input:

999999999999978053 20

output:

856342931

result:

ok 1 number(s): "856342931"

Test #22:

score: 0
Accepted
time: 122ms
memory: 11392kb

input:

997545214682632383 22

output:

611358320

result:

ok 1 number(s): "611358320"

Test #23:

score: 0
Accepted
time: 126ms
memory: 11424kb

input:

999999999999999999 22

output:

675578869

result:

ok 1 number(s): "675578869"

Test #24:

score: 0
Accepted
time: 121ms
memory: 11648kb

input:

419076504441583762 22

output:

48383442

result:

ok 1 number(s): "48383442"

Test #25:

score: 0
Accepted
time: 126ms
memory: 11392kb

input:

318 50

output:

179936804

result:

ok 1 number(s): "179936804"

Test #26:

score: 0
Accepted
time: 122ms
memory: 11364kb

input:

222 50

output:

727197189

result:

ok 1 number(s): "727197189"

Test #27:

score: 0
Accepted
time: 126ms
memory: 11408kb

input:

999999999999999999 50

output:

925729462

result:

ok 1 number(s): "925729462"

Test #28:

score: 0
Accepted
time: 119ms
memory: 11652kb

input:

762200545525776 75

output:

327716882

result:

ok 1 number(s): "327716882"

Test #29:

score: 0
Accepted
time: 123ms
memory: 11368kb

input:

138288 81

output:

445898304

result:

ok 1 number(s): "445898304"

Test #30:

score: 0
Accepted
time: 127ms
memory: 11584kb

input:

659457709 81

output:

452473813

result:

ok 1 number(s): "452473813"

Test #31:

score: 0
Accepted
time: 127ms
memory: 11648kb

input:

999999990717779391 81

output:

794519551

result:

ok 1 number(s): "794519551"

Test #32:

score: 0
Accepted
time: 123ms
memory: 11440kb

input:

436978356910906711 100

output:

137492099

result:

ok 1 number(s): "137492099"

Test #33:

score: 0
Accepted
time: 139ms
memory: 11644kb

input:

999999996592424938 200

output:

731073159

result:

ok 1 number(s): "731073159"

Test #34:

score: 0
Accepted
time: 140ms
memory: 11460kb

input:

999999999999999999 200

output:

509983346

result:

ok 1 number(s): "509983346"

Test #35:

score: 0
Accepted
time: 135ms
memory: 11644kb

input:

1000000000000000000 200

output:

441545728

result:

ok 1 number(s): "441545728"

Test #36:

score: 0
Accepted
time: 159ms
memory: 11480kb

input:

16982382700142252 272

output:

436113233

result:

ok 1 number(s): "436113233"

Test #37:

score: 0
Accepted
time: 170ms
memory: 11700kb

input:

1000000000000000000 300

output:

464643821

result:

ok 1 number(s): "464643821"

Test #38:

score: 0
Accepted
time: 170ms
memory: 11492kb

input:

999999999999999999 300

output:

383551773

result:

ok 1 number(s): "383551773"

Test #39:

score: 0
Accepted
time: 162ms
memory: 11516kb

input:

999995030025107023 300

output:

867118476

result:

ok 1 number(s): "867118476"

Test #40:

score: 0
Accepted
time: 215ms
memory: 11452kb

input:

8163 400

output:

971517282

result:

ok 1 number(s): "971517282"

Test #41:

score: 0
Accepted
time: 226ms
memory: 11512kb

input:

1000000000000000000 400

output:

581335073

result:

ok 1 number(s): "581335073"

Test #42:

score: 0
Accepted
time: 247ms
memory: 11460kb

input:

999999999999999999 426

output:

298358370

result:

ok 1 number(s): "298358370"

Test #43:

score: 0
Accepted
time: 243ms
memory: 11648kb

input:

1420 426

output:

952985679

result:

ok 1 number(s): "952985679"

Test #44:

score: 0
Accepted
time: 263ms
memory: 11492kb

input:

863118 445

output:

237379873

result:

ok 1 number(s): "237379873"

Test #45:

score: 0
Accepted
time: 263ms
memory: 11456kb

input:

3822817 445

output:

818252692

result:

ok 1 number(s): "818252692"

Test #46:

score: 0
Accepted
time: 260ms
memory: 11412kb

input:

999999999999999999 447

output:

774884223

result:

ok 1 number(s): "774884223"

Test #47:

score: 0
Accepted
time: 256ms
memory: 11640kb

input:

148755911871216926 447

output:

355549012

result:

ok 1 number(s): "355549012"

Test #48:

score: 0
Accepted
time: 301ms
memory: 11408kb

input:

1000000000000000000 492

output:

980334224

result:

ok 1 number(s): "980334224"

Test #49:

score: 0
Accepted
time: 301ms
memory: 11456kb

input:

999999999999999348 492

output:

482780786

result:

ok 1 number(s): "482780786"

Test #50:

score: 0
Accepted
time: 309ms
memory: 11404kb

input:

999999884436856972 492

output:

892292610

result:

ok 1 number(s): "892292610"

Test #51:

score: 0
Accepted
time: 310ms
memory: 11668kb

input:

1399 493

output:

984913617

result:

ok 1 number(s): "984913617"

Test #52:

score: 0
Accepted
time: 310ms
memory: 11492kb

input:

999999999999999999 493

output:

177173159

result:

ok 1 number(s): "177173159"

Test #53:

score: 0
Accepted
time: 302ms
memory: 11476kb

input:

5690586664 493

output:

306771535

result:

ok 1 number(s): "306771535"

Test #54:

score: 0
Accepted
time: 315ms
memory: 11380kb

input:

1727132392490 497

output:

4203841

result:

ok 1 number(s): "4203841"

Test #55:

score: 0
Accepted
time: 318ms
memory: 11484kb

input:

1358 498

output:

80348265

result:

ok 1 number(s): "80348265"

Test #56:

score: 0
Accepted
time: 316ms
memory: 11428kb

input:

1000000000000000000 498

output:

166818138

result:

ok 1 number(s): "166818138"

Test #57:

score: 0
Accepted
time: 317ms
memory: 11672kb

input:

999999999999923208 499

output:

710616059

result:

ok 1 number(s): "710616059"

Test #58:

score: 0
Accepted
time: 313ms
memory: 11484kb

input:

999999999999999999 499

output:

951659064

result:

ok 1 number(s): "951659064"

Test #59:

score: 0
Accepted
time: 313ms
memory: 11492kb

input:

1000000000000000000 499

output:

945692946

result:

ok 1 number(s): "945692946"

Test #60:

score: 0
Accepted
time: 318ms
memory: 11648kb

input:

246568444718418 500

output:

378699829

result:

ok 1 number(s): "378699829"

Test #61:

score: 0
Accepted
time: 314ms
memory: 11468kb

input:

1156 500

output:

997092726

result:

ok 1 number(s): "997092726"

Test #62:

score: 0
Accepted
time: 318ms
memory: 11644kb

input:

166067991026698932 500

output:

155266353

result:

ok 1 number(s): "155266353"