結果

問題 No.673 カブトムシ
ユーザー maspy
提出日時 2020-02-05 21:09:42
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 530 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-07-02 23:45:54
合計ジャッジ時間 1,538 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

B,C,D = map(int,read().split())

MOD = 10**9 + 7

def power(n):
    """return x^n modulo x^2 - (C+1) x + C"""
    if n == 0:
        return 1, 0
    a,b = power(n//2)
    a,b = a*a - C * b * b, 2 * a * b + (C+1) * b * b
    a,b = a % MOD, b % MOD
    if n % 2 == 0:
        return a,b
    a,b = -C * b, a + (C+1) * b
    a,b = a % MOD, b % MOD
    return a,b

a,b = power(D)
answer = B * b * C % MOD
print(answer)
0