QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#569805 | #9330. Series Sum | Crysfly | AC ✓ | 96ms | 16616kb | C++14 | 2.9kb | 2024-09-17 11:00:28 | 2024-09-17 11:00:29 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define mod 998244353
struct modint{
unsigned int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x<o.x?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,modint b){return a.x==b.x;}
friend bool operator !=(modint a,modint b){return a.x!=b.x;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 1000006
#define inf 0x3f3f3f3f
int p,k;
void work()
{
k=read(),p=read();
modint res=0;
modint now=0;
For(i,k,p*k) now+=C(i,k)*sign(i-k);
For(d,k,p*k){
res+=qpow(C(d,k),p)*now;
int a=p*k-d;
now-=sign(a)*(C(p*k,a)+C(p*k,a-1));
now*=((mod+1)/2);
// cout<<"coe "<<d+1<<" "<<now.x<<"\n";
}
/*
for all i: find
i->i+1
\sum_j C(j,i)*(-1)^{j-i}
\sum_j C(j,i+1)
*/
// For(len,k,p*k)
// For(c,0,len-k)
// res+=sign(c)*C(len,c)*qpow(C(len-c,k),p);
res*=2;
cout<<res.x<<"\n";
}
signed main()
{
int T=read();
while(T--)work();
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
input:
3 2 3 1 10 9 6
output:
818 204495126 16726290
result:
ok 3 number(s): "818 204495126 16726290"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
3 10 1 1 3 1 2
output:
2 26 6
result:
ok 3 number(s): "2 26 6"
Test #3:
score: 0
Accepted
time: 42ms
memory: 3500kb
input:
2112 16 51 27 30 32 22 6 69 1 7 6 40 15 63 23 37 11 57 6 92 8 62 5 50 11 76 1 57 99 8 2 90 35 10 13 54 6 33 8 70 14 48 12 63 7 99 85 7 14 60 7 78 22 22 1 53 6 61 2 67 8 68 5 67 7 57 8 79 11 29 15 44 8 62 19 39 9 71 3 65 3 83 6 16 11 86 7 25 124 6 1 21 5 76 17 35 14 29 1 55 67 13 987 1 8 27 4 99 8 19...
output:
958728366 182850046 337462356 238321759 94586 688819126 880558546 673294800 592760052 772846256 555807947 834237048 258386591 443217990 83210442 741605708 687991731 380324156 884202426 190172937 130140451 931313604 659396498 344165836 434542961 111646504 6836992 571531367 631528990 880394933 1976309...
result:
ok 2112 numbers
Test #4:
score: 0
Accepted
time: 96ms
memory: 7348kb
input:
6 1 164257 7 10955 1 30358 1 198674 1 206507 1 323519
output:
450748134 285759990 479497879 856048370 75480834 220335166
result:
ok 6 numbers
Test #5:
score: 0
Accepted
time: 91ms
memory: 13520kb
input:
4 62 12597 13 15082 2 11295 1 330
output:
134578883 817592796 66930551 383110659
result:
ok 4 number(s): "134578883 817592796 66930551 383110659"
Test #6:
score: 0
Accepted
time: 36ms
memory: 3640kb
input:
1009 31 32 25 40 41 24 500 2 29 34 38 26 38 26 90 11 200 5 71 14 50 20 34 29 47 21 125 8 111 9 37 27 142 7 45 22 125 8 27 36 58 17 27 36 35 28 28 35 43 23 125 8 333 3 32 31 71 14 25 39 100 10 35 28 27 36 47 21 27 37 66 15 47 21 25 40 37 27 34 29 45 22 35 28 66 15 333 3 50 20 25 39 25 39 26 38 76 13 ...
output:
871402622 419577502 603695744 784359155 759347810 51557094 51557094 712633402 954410959 616922676 816335450 256771489 866916495 760989591 859187268 459975997 550880541 525468303 760989591 277034910 243040669 277034910 631662375 200080307 141253289 760989591 775322262 996562074 616922676 86443311 524...
result:
ok 1009 numbers
Test #7:
score: 0
Accepted
time: 37ms
memory: 3784kb
input:
208 139 31 117 45 41 41 267 35 82 16 3 45 181 41 1219 8 31 44 1528 5 235 4 222 10 269 26 827 2 870 7 16 23 263 25 11 26 660 15 129 41 141 11 64 36 100 49 122 50 276 27 44 11 128 24 217 37 335 14 24 49 237 39 418 18 48 35 94 33 375 16 4 47 121 39 95 12 858 7 304 31 370 21 182 33 194 15 55 6 202 13 24...
output:
851150545 222205624 161298067 690708886 622565881 900621090 661760377 251742611 60893316 648664643 49553591 112014667 919771321 587648714 771905571 833478149 713320155 677714356 137765434 3585171 981954406 488903479 513181593 874511965 16170849 442603529 950708093 985481603 369032829 887191778 69043...
result:
ok 208 numbers
Test #8:
score: 0
Accepted
time: 89ms
memory: 16616kb
input:
1 1000 1000
output:
783050993
result:
ok 1 number(s): "783050993"
Test #9:
score: 0
Accepted
time: 5ms
memory: 3648kb
input:
10 100 100 99 101 98 102 97 103 96 104 101 99 102 98 103 97 104 96 105 95
output:
745474847 348955190 781334174 938153402 358565847 695815461 196183578 379968206 129529953 29572094
result:
ok 10 numbers
Test #10:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
6 3 2 4 4 3 3 3 5 5 3 4 5
output:
126 124014359 32162 328827205 64386506 567277979
result:
ok 6 numbers
Test #11:
score: 0
Accepted
time: 55ms
memory: 4644kb
input:
10 100 1000 1000 100 250 400 400 250 25000 4 5 20000 10 10000 10000 10 20000 5 4 25000
output:
354756979 228119416 829496936 168882209 168334375 302715191 745862435 202616186 375396996 520541595
result:
ok 10 numbers
Test #12:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
10 7 7 5 8 10 4 13 2 2 15 3 9 8 8 6 9 5 3 4 10
output:
629286899 91930612 465722397 823378532 871380528 417689043 815208695 887739621 64386506 566247517
result:
ok 10 numbers