結果
問題 | No.303 割れません |
ユーザー | rpy3cpp |
提出日時 | 2017-10-12 23:32:38 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 876 bytes |
コンパイル時間 | 324 ms |
コンパイル使用メモリ | 86,764 KB |
実行使用メモリ | 262,972 KB |
最終ジャッジ日時 | 2023-08-11 00:01:46 |
合計ジャッジ時間 | 17,547 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 66 ms
71,428 KB |
testcase_01 | AC | 66 ms
71,180 KB |
testcase_02 | AC | 67 ms
71,388 KB |
testcase_03 | RE | - |
testcase_04 | TLE | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
ソースコード
def solve(L): if L == 1: return 1, 1 elif L == 2: return 4, 1 # 3を買ってきて切る elif L & 1: return L, fib(L) else: return L, 2 * fibfib(L//2) def fib(L): '''a1 = fib(2*k), a0 = fib(2*k-1) ''' k = (L + 1) // 2 a1, a0 = 0, 1 p1, p0 = 1, 1 while k: if k & 1: ac = a1 * p1 a1 = ac + a1*p0 + a0*p1 a0 = ac + a0*p0 p2 = p1 * p1 p1 = p2 + 2*p1*p0 p0 = p2 + p0*p0 k >>= 1 if L & 1: return a0 else: return a1 def fibfib(m): '''fib(m)*fib(m-1) ''' if m == 1: return 0 if m == 2: return 1 # fib(2)*fib(1) = 1 a = 1 b = 1 for i in range(m - 2): a, b = a + b, a return a * b L = int(input()) cost, n_pat = solve(L) print(cost) print(n_pat)