QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#562421 | #8184. Different Summands Counting | Afterlife# | WA | 310ms | 11472kb | C++20 | 2.0kb | 2024-09-13 17:28:30 | 2024-09-13 17:28:31 |
Judging History
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) % mod;
else ans = (ans - g[i]) % mod ;
}
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 126ms
memory: 11344kb
input:
10 2
output:
17
result:
ok 1 number(s): "17"
Test #2:
score: 0
Accepted
time: 118ms
memory: 11400kb
input:
20 4
output:
3413
result:
ok 1 number(s): "3413"
Test #3:
score: 0
Accepted
time: 126ms
memory: 11384kb
input:
30 7
output:
2405830
result:
ok 1 number(s): "2405830"
Test #4:
score: 0
Accepted
time: 122ms
memory: 11400kb
input:
25 4
output:
7336
result:
ok 1 number(s): "7336"
Test #5:
score: -100
Wrong Answer
time: 310ms
memory: 11472kb
input:
1000000000000000000 500
output:
767396010
result:
wrong answer 1st numbers differ - expected: '423462987', found: '767396010'