結果

問題 No.303 割れません
ユーザー maspy
提出日時 2023-07-22 16:49:23
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,186 ms / 10,000 ms
コード長 526 bytes
コンパイル時間 539 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 15,488 KB
最終ジャッジ日時 2024-09-22 16:29:41
合計ジャッジ時間 10,927 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.set_int_max_str_digits(10**7)
L = int(read())

if L == 2:
    print(3)
    print('INF')
    exit()


def fibonacci(n):
    # x^n = a + bx mod x^2-x-1
    if n == 0:
        return 1, 0
    a, b = fibonacci(n // 2)
    c = b * b
    a, b = a * a + c, 2 * a * b + c
    return (b, a + b) if n & 1 else (a, b)


_, x = fibonacci(L)
if L % 2 == 0:
    _, y = fibonacci(L // 2)
    x -= y * y
print(L)
print(x)
0