QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#168275#6417. Classical Summation ProblemFeet_McYeetWA 14ms19148kbC++202.1kb2023-09-08 05:09:072023-09-08 05:09:08

Judging History

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

  • [2023-09-08 05:09:08]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:19148kb
  • [2023-09-08 05:09:07]
  • 提交

answer

#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <iterator>
#include <algorithm>
#include <bit>
#include <numeric>
#include <iomanip>
#include <bitset>
using namespace std;
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
#define el << '\n'
#define nl cout << '\n'
#define cina(a,n) for (int i=0; i<n; i++) cin >> a[i]
#define ll long long
#define spc << ' '
#define forn(i,n) for (int i=0; i<n; i++)
#define forl(i,s,e) for (int i=s; i<e; i++)
#define pb push_back
#define ansyes cout << "YES\n"
#define ansno cout << "NO\n"
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pss pair<short, short>
#define MAX *max_element
#define MIN *min_element
#define rsz resize
#define sz(x) ((int) x.size())
#define all(x) x.begin(), x.end()
#define bsi(x, v) (int) (lower_bound(x.begin(), x.end(), v) - x.begin());
const int inf = 1000000000;
const ll inf2 = 4000000000000000000;

const int MOD = 998244353;

ll fpow(int a, int b) {
    if (b==0) return 1;
    if (b%2) return (a*fpow(a,b-1))%MOD;
    ll temp = fpow(a,b/2);
    return (temp*temp)%MOD;
}

const int MAXN = 1000005;
ll fact[MAXN];
ll ifact[MAXN];

void ppf() {
    fact[0] = 1;
    forl(i,1,MAXN) fact[i] = (fact[i-1]*i)%MOD;
    ifact[MAXN-1] = fpow(fact[MAXN-1],MOD-2);
    for (int i = MAXN-1; i>0; i--) ifact[i-1] = (ifact[i]*i)%MOD;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ppf();
    int n, k; cin >> n >> k;
    if (k%2) {
        cout << ((fpow(n,k)*(n+1))%MOD*fpow(2,MOD-2))%MOD;
    }
    else {
        ll d = 0;
        forn(i,n-1) {
            d += (fpow(i+1, k/2) * fpow(n-i-1, k/2))%MOD;
        }
        d *= fpow(fpow(n, MOD-2), k);
        d %= MOD;
        d *= fact[k];
        d %= MOD;
        d *= ifact[k/2];
        d %= MOD;
        d *= ifact[k/2];
        d %= MOD;
        d = -d + (n+1) + MOD;
        d %= MOD;
        d *= fpow(2, MOD-2);
        d %= MOD;
        cout << (d * fpow(n,k))%MOD;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 19016kb

input:

3 2

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: 0
Accepted
time: 14ms
memory: 19128kb

input:

5 3

output:

375

result:

ok 1 number(s): "375"

Test #3:

score: 0
Accepted
time: 4ms
memory: 19068kb

input:

2 2

output:

5

result:

ok 1 number(s): "5"

Test #4:

score: 0
Accepted
time: 8ms
memory: 19032kb

input:

10 9

output:

508778235

result:

ok 1 number(s): "508778235"

Test #5:

score: 0
Accepted
time: 9ms
memory: 19132kb

input:

69 3

output:

11497815

result:

ok 1 number(s): "11497815"

Test #6:

score: 0
Accepted
time: 8ms
memory: 19148kb

input:

994 515

output:

33689623

result:

ok 1 number(s): "33689623"

Test #7:

score: -100
Wrong Answer
time: 12ms
memory: 19016kb

input:

4476 6182

output:

974968359

result:

wrong answer 1st numbers differ - expected: '114894183', found: '974968359'