結果
問題 | No.2883 K-powered Sum of Fibonacci |
ユーザー | hiro1729 |
提出日時 | 2024-09-07 16:50:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 64 ms / 3,000 ms |
コード長 | 2,244 bytes |
コンパイル時間 | 612 ms |
コンパイル使用メモリ | 82,596 KB |
実行使用メモリ | 72,840 KB |
最終ジャッジ日時 | 2024-09-07 16:50:46 |
合計ジャッジ時間 | 4,269 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
54,952 KB |
testcase_01 | AC | 37 ms
54,584 KB |
testcase_02 | AC | 44 ms
64,176 KB |
testcase_03 | AC | 43 ms
63,012 KB |
testcase_04 | AC | 43 ms
60,932 KB |
testcase_05 | AC | 56 ms
69,140 KB |
testcase_06 | AC | 51 ms
65,476 KB |
testcase_07 | AC | 58 ms
71,492 KB |
testcase_08 | AC | 60 ms
69,220 KB |
testcase_09 | AC | 55 ms
68,724 KB |
testcase_10 | AC | 53 ms
66,984 KB |
testcase_11 | AC | 61 ms
71,412 KB |
testcase_12 | AC | 56 ms
66,920 KB |
testcase_13 | AC | 55 ms
67,932 KB |
testcase_14 | AC | 59 ms
71,292 KB |
testcase_15 | AC | 56 ms
69,028 KB |
testcase_16 | AC | 39 ms
54,704 KB |
testcase_17 | AC | 58 ms
68,724 KB |
testcase_18 | AC | 53 ms
66,536 KB |
testcase_19 | AC | 59 ms
68,676 KB |
testcase_20 | AC | 61 ms
71,724 KB |
testcase_21 | AC | 60 ms
71,248 KB |
testcase_22 | AC | 60 ms
71,416 KB |
testcase_23 | AC | 61 ms
71,544 KB |
testcase_24 | AC | 62 ms
71,692 KB |
testcase_25 | AC | 64 ms
72,724 KB |
testcase_26 | AC | 62 ms
71,360 KB |
testcase_27 | AC | 61 ms
72,840 KB |
testcase_28 | AC | 60 ms
72,288 KB |
testcase_29 | AC | 60 ms
72,060 KB |
testcase_30 | AC | 59 ms
70,612 KB |
testcase_31 | AC | 50 ms
65,792 KB |
testcase_32 | AC | 49 ms
65,792 KB |
testcase_33 | AC | 59 ms
70,572 KB |
testcase_34 | AC | 48 ms
64,692 KB |
testcase_35 | AC | 38 ms
54,128 KB |
testcase_36 | AC | 38 ms
56,120 KB |
testcase_37 | AC | 42 ms
61,372 KB |
testcase_38 | AC | 45 ms
62,204 KB |
testcase_39 | AC | 46 ms
62,920 KB |
testcase_40 | AC | 43 ms
61,064 KB |
testcase_41 | AC | 38 ms
55,244 KB |
testcase_42 | AC | 61 ms
71,428 KB |
ソースコード
class Comb: def __init__(self, N, mod = 998244353): self.n = N self.mod = mod self.fac = [0] * (self.n + 1) self.invf = [0] * (self.n + 1) self.inv = [0] * (self.n + 1) self.fac[0] = 1 self.fac[1] = 1 self.invf[0] = 1 self.invf[1] = 1 self.inv[1] = 1 for i in range(2, self.n + 1): self.fac[i] = self.fac[i - 1] * i % self.mod self.inv[i] = self.mod - self.inv[self.mod % i] * (self.mod // i) % self.mod self.invf[i] = self.invf[i - 1] * self.inv[i] % self.mod def F(self, N): return self.fac[N] def C(self, N, K): return self.invf[K] * self.invf[N - K] % self.mod * self.fac[N] % self.mod def P(self, N, K): return self.invf[N - K] * self.fac[N] % self.mod def H(self, N, K): return self.invf[K] * self.invf[N - 1] % self.mod * self.fac[N + K - 1] % self.mod # a + b √5 mod = 998244353 class Q_v5: def __init__(self, a, b): self.a = a % mod self.b = b % mod def __add__(self, other): return self.__class__((self.a + other.a) % mod, (self.b + other.b) % mod) def __sub__(self, other): return self.__class__((self.a - other.a) % mod, (self.b - other.b) % mod) def __mul__(self, other): return self.__class__((self.a * other.a + self.b * other.b * 5) % mod, (self.a * other.b + self.b * other.a) % mod) def __truediv__(self, other): other_inv = pow(other.a * other.a - 5 * other.b * other.b, mod - 2, mod) return self.__class__((self.a * other.a - 5 * self.b * other.b) * other_inv % mod, (other.a * self.b - self.a * other.b) * other_inv % mod) def __neg__(self): return self.__class__(-self.a % mod, -self.b % mod) def __str__(self): return str(self.a) + ' + ' + str(self.b) + ' √5' # 繰り返し二乗法 def pow_(a: Q_v5, n: int): res = Q_v5(1, 0) now = a for i in range(100): if n & (1 << i): res = res * now now = now * now return res N, K = map(int, input().split()) c = Comb(1000) sm = Q_v5(0, 0) inv2 = 499122177 a = Q_v5(inv2, inv2) b = Q_v5(inv2, -inv2) for i in range(K + 1): p = c.C(K, i) * (1 if i % 2 == 0 else -1) % mod x = pow_(a, K - i) * pow_(b, i) # x^1 + ... + x^N if x.a == 1 and x.b == 0: sm = sm + Q_v5(p * N, 0) else: sm = sm + Q_v5(p, 0) * (pow_(x, N + 1) - x) / (x - Q_v5(1, 0)) sm = sm / pow_(Q_v5(0, 1), K) print(sm.a)