hihoCoder Challenge 28 register

Ended

Participants:391

Verdict:Accepted
Submitted:2017-04-23 19:31:40

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<bits/stdc++.h>
#define ll long long
#define mod 998244353
#define N 1000005
using namespace std;
int n,pw[N],fac[N],inv[N],finv[N];
int ksm(int x,int y){
    int z=1; for (; y; y>>=1,x=(ll)x*x%mod) if (y&1) z=(ll)z*x%mod;
    return z;   
}
int calc(int x){
    //cout<<x<<' '<<(ll)fac[n-2]%mod*finv[n-2-(x-1)]%mod*finv[x-1]%mod*pw[n-2-(x-1)]%mod<<endl;
    return (ll)fac[n-2]%mod*finv[n-2-(x-1)]%mod*finv[x-1]%mod*pw[n-2-(x-1)]%mod;
}
int main(){
    scanf("%d",&n);
    if (n==1){ puts("0"); return 0; }
    int i,p;
    fac[0]=pw[0]=inv[0]=finv[0]=inv[1]=1;
    for (i=1; i<=n; i++) pw[i]=(ll)pw[i-1]*(n-1)%mod;
    for (i=1; i<=n; i++) fac[i]=(ll)fac[i-1]*i%mod;
    for (i=2; i<=n; i++) inv[i]=mod-(ll)inv[mod%i]*(mod/i)%mod;
    for (i=1; i<=n; i++) finv[i]=(ll)finv[i-1]*inv[i]%mod;
//  cout<<inv[n]<<endl;
    p=2ll*(n-1)*inv[n]%mod;
    //cout<<p<<endl;
    int ans=(ll)p*p%mod*ksm(n,n-2)%mod;
//  cout<<ans<<endl;
    //cout<<"   "<<(ll)1*1-2ll*1*p%mod<<endl;
    for (i=1; i<n; i++){
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX