結果

問題 No.980 Fibonacci Convolution Hard
ユーザー 👑 tamatotamato
提出日時 2020-01-31 23:08:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 574 ms / 2,000 ms
コード長 679 bytes
コンパイル時間 1,654 ms
コンパイル使用メモリ 81,012 KB
実行使用メモリ 106,672 KB
最終ジャッジ日時 2023-10-17 13:48:53
合計ジャッジ時間 14,331 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 553 ms
106,084 KB
testcase_01 AC 534 ms
106,448 KB
testcase_02 AC 531 ms
106,488 KB
testcase_03 AC 539 ms
106,464 KB
testcase_04 AC 537 ms
106,604 KB
testcase_05 AC 522 ms
106,396 KB
testcase_06 AC 542 ms
106,312 KB
testcase_07 AC 542 ms
106,608 KB
testcase_08 AC 522 ms
106,324 KB
testcase_09 AC 536 ms
106,480 KB
testcase_10 AC 529 ms
106,432 KB
testcase_11 AC 540 ms
106,512 KB
testcase_12 AC 531 ms
106,576 KB
testcase_13 AC 528 ms
106,564 KB
testcase_14 AC 574 ms
106,672 KB
testcase_15 AC 524 ms
106,620 KB
testcase_16 AC 493 ms
106,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.readline

    mod = 1000000007
    p = int(input())
    N = 2*10**6
    A = [0] * (N+1)
    A[2] = 1
    for i in range(3, N+1):
        A[i] = ((p * A[i-1])%mod + A[i-2])%mod

    ans = [0] * (N+1)
    for i in range(4, N+1):
        if i % 2 == 0:
            ans[i] = ((p * ans[i-1])%mod + (ans[i-2] + (pow(A[i//2], 2, mod) + pow(A[i//2 - 1], 2, mod))%mod)%mod)%mod
        else:
            ans[i] = (((p * (ans[i-1] + pow(A[(i-1)//2], 2, mod))%mod)%mod + ans[i-2])%mod + (A[i//2] * A[i//2 - 1] * 2)%mod)%mod
    Q = int(input())
    for _ in range(Q):
        print(ans[int(input())])


if __name__ == '__main__':
    main()
0