QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#472554 | #6417. Classical Summation Problem | UESTC_DebugSimulator# | WA | 13ms | 19328kb | C++17 | 1.0kb | 2024-07-11 17:08:33 | 2024-07-11 17:08:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define md 998244353
#define N 1000010
int n,k;
int f[N],inv[N];
int ans,x;
int C(int m,int n)
{
if(n>m) return 0;
return(f[m]*inv[m-n]%md*inv[n]%md);
}
int qp(int a,int n)
{
int res=1;
while(n)
{
if(n&1) res=res*a%md;
a=a*a%md;
n>>=1;
}
return res;
}
int invv(int a)
{
return qp(a,md-2);
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
f[0]=f[1]=inv[0]=inv[1]=1;
for(int i=2;i<=1e6;i++) f[i]=f[i-1]*i%md,inv[i]=(md-md/i)*inv[md%i]%md;
for(int i=1;i<=1e6;i++) inv[i]=inv[i-1]*inv[i]%md;
cin>>n>>k;
if(k&1)
{
ans=qp(n,k)*(n+1)/2;
ans=ans%md;
cout<<ans<<"\n";
}
else
{
ans=qp(n,k)*(n+1)%md*invv(2)%md;
//cout<<ans<<"\n";
x=0;
int n1=k/2;
for(int i=1;i<n;i++)
{
x=(x+(C(k,n1)%md*qp(i,n1)%md*qp(n-i,n1)%md))%md;
}
//cout<<x<<"\n";
//x=x*invv(qp(n,k))%md;
x=x*invv(2)%md;
ans=ans-x;
while(ans<0) ans=ans+md;
cout<<ans<<"\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 10ms
memory: 19324kb
input:
3 2
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 12ms
memory: 19328kb
input:
5 3
output:
375
result:
ok 1 number(s): "375"
Test #3:
score: 0
Accepted
time: 13ms
memory: 19256kb
input:
2 2
output:
5
result:
ok 1 number(s): "5"
Test #4:
score: -100
Wrong Answer
time: 8ms
memory: 19240kb
input:
10 9
output:
9656058
result:
wrong answer 1st numbers differ - expected: '508778235', found: '9656058'