結果

問題 No.1275 綺麗な式
ユーザー marroncastlemarroncastle
提出日時 2020-10-30 22:04:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 820 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 70,964 KB
最終ジャッジ日時 2023-09-29 06:09:35
合計ジャッジ時間 7,174 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
70,584 KB
testcase_01 AC 73 ms
70,760 KB
testcase_02 AC 73 ms
70,808 KB
testcase_03 AC 75 ms
70,816 KB
testcase_04 AC 73 ms
70,920 KB
testcase_05 AC 72 ms
70,776 KB
testcase_06 AC 73 ms
70,784 KB
testcase_07 AC 71 ms
70,840 KB
testcase_08 AC 75 ms
70,676 KB
testcase_09 AC 74 ms
70,908 KB
testcase_10 AC 73 ms
70,804 KB
testcase_11 AC 74 ms
70,760 KB
testcase_12 AC 72 ms
70,580 KB
testcase_13 AC 74 ms
70,680 KB
testcase_14 AC 72 ms
70,800 KB
testcase_15 AC 74 ms
70,872 KB
testcase_16 AC 72 ms
70,916 KB
testcase_17 AC 74 ms
70,868 KB
testcase_18 AC 73 ms
70,900 KB
testcase_19 AC 70 ms
70,912 KB
testcase_20 AC 71 ms
70,912 KB
testcase_21 AC 70 ms
70,716 KB
testcase_22 AC 72 ms
70,868 KB
testcase_23 AC 71 ms
70,900 KB
testcase_24 AC 73 ms
70,700 KB
testcase_25 AC 74 ms
70,916 KB
testcase_26 AC 73 ms
70,964 KB
testcase_27 AC 74 ms
70,760 KB
testcase_28 AC 71 ms
70,796 KB
testcase_29 AC 71 ms
70,900 KB
testcase_30 AC 73 ms
70,868 KB
testcase_31 AC 71 ms
70,964 KB
testcase_32 AC 72 ms
70,888 KB
testcase_33 AC 71 ms
70,916 KB
testcase_34 AC 72 ms
70,808 KB
testcase_35 AC 71 ms
70,900 KB
testcase_36 AC 69 ms
70,780 KB
testcase_37 AC 72 ms
70,768 KB
testcase_38 AC 72 ms
70,756 KB
testcase_39 AC 72 ms
70,716 KB
testcase_40 AC 71 ms
70,692 KB
testcase_41 AC 71 ms
70,688 KB
testcase_42 AC 71 ms
70,908 KB
testcase_43 AC 71 ms
70,776 KB
testcase_44 AC 71 ms
70,724 KB
testcase_45 AC 74 ms
70,904 KB
testcase_46 AC 72 ms
70,688 KB
testcase_47 AC 73 ms
70,808 KB
testcase_48 AC 74 ms
70,708 KB
testcase_49 AC 70 ms
70,800 KB
testcase_50 AC 71 ms
70,764 KB
testcase_51 AC 80 ms
70,956 KB
testcase_52 AC 71 ms
70,908 KB
testcase_53 AC 71 ms
70,716 KB
testcase_54 AC 71 ms
70,964 KB
testcase_55 AC 71 ms
70,820 KB
testcase_56 AC 72 ms
70,840 KB
testcase_57 AC 71 ms
70,816 KB
testcase_58 AC 71 ms
70,804 KB
testcase_59 AC 72 ms
70,864 KB
testcase_60 AC 73 ms
70,696 KB
testcase_61 AC 72 ms
70,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def power(x,n,mod):
  digit = len(str(bin(n)))-2
  a = len(x)
  dp = [x]*digit
  for i in range(1,digit):
    dp[i] = dot(dp[i-1],dp[i-1],mod)
  ans = [[0]*a for _ in range(a)]
  for i in range(a):
    ans[i][i] = 1
  for i in range(digit):
    if 1<<i & n:
      ans = dot(dp[i],ans,mod)
  return ans

def dot(A,B,mod):
  p = len(A)
  q = len(A[0])
  r = len(B)
  s = len(B[0])
  if q!=r:
    print('掛け算できません')
    return
  ans = [[0]*s for _ in range(p)]
  for i in range(p):
    for j in range(s):
      for k in range(q):
        ans[i][j] += A[i][k]*B[k][j]
        ans[i][j] %= mod
  return ans

def solve():
  a, b = map(int, input().split())
  N = int(input())
  init = [[1],[0]]
  mat = [[a,b],[1,a]]
  mod = 10**9+7
  ans = dot(power(mat,N,mod),init,mod)[0][0]
  return ans*2%mod
print(solve())
0