Submit Info #29439

Problem Lang User Status Time Memory
$\sum_{i=0}^{\infty} r^i i^d$ pypy3 onakasuitacity AC 4305 ms 259.70 MiB

ケース詳細
Name Status Time Memory
0_00 AC 49 ms 29.80 MiB
0_01 AC 50 ms 29.84 MiB
0_02 AC 3682 ms 259.64 MiB
2_00 AC 52 ms 29.74 MiB
2_01 AC 46 ms 29.85 MiB
2_02 AC 63 ms 30.08 MiB
2_03 AC 214 ms 41.57 MiB
2_04 AC 4305 ms 259.70 MiB
2_05 AC 3676 ms 259.69 MiB
example_00 AC 50 ms 29.84 MiB

import sys INF = 1 << 60 MOD = 998244353 sys.setrecursionlimit(2147483647) input = lambda:sys.stdin.readline().rstrip() def resolve(): r, d = map(int, input().split()) power = [1] * (d + 2) fact = [1] * (d + 2) for i in range(1, d + 2): power[i] = power[i - 1] * r % MOD fact[i] = fact[i - 1] * i % MOD invfact = [0] * (d + 2) invfact[d + 1] = pow(fact[d + 1], MOD - 2, MOD) for i in range(d, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % MOD comb = lambda n, k : fact[n] * invfact[k] % MOD * invfact[n - k] % MOD if 0 <= k <= n else 0 res = 0 s = 0 for k in range(d + 1): s += pow(k + 1, d, MOD) * power[k + 1] s %= MOD if (d - k) & 1: res -= power[d - k] * comb(d + 1, k + 1) % MOD * s else: res += power[d - k] * comb(d + 1, k + 1) % MOD * s res %= MOD res *= pow(1 - r, -(d + 1) % (MOD - 1), MOD) res += d == 0 res %= MOD print(res) resolve()