結果
| 問題 |
No.891 隣接3項間の漸化式
|
| コンテスト | |
| ユーザー |
buey_t
|
| 提出日時 | 2023-03-12 19:37:19 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,886 bytes |
| コンパイル時間 | 347 ms |
| コンパイル使用メモリ | 81,536 KB |
| 実行使用メモリ | 89,216 KB |
| 最終ジャッジ日時 | 2024-09-18 07:12:13 |
| 合計ジャッジ時間 | 7,507 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 WA * 2 |
ソースコード
def main():
try:
import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')
except:
pass
try:
import sys
sys.setrecursionlimit(10**7)
except:
pass
from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum
from heapq import heapify, heappop, heappush
from bisect import bisect_left, bisect_right
from copy import deepcopy
import copy
import random
from collections import deque,Counter,defaultdict
from itertools import permutations,combinations
from decimal import Decimal,ROUND_HALF_UP
#tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
from functools import lru_cache, reduce
#@lru_cache(maxsize=None)
from operator import add,sub,mul,xor,and_,or_,itemgetter
INF = 10**18
mod1 = 10**9+7
mod2 = 998244353
#DecimalならPython
'''
自明解は避ける
'''
def matmul(A,B,mod):
res = [[0]*len(B[0]) for _ in [None]*len(A)]
for i, resi in enumerate(res):
for k, aik in enumerate(A[i]):
for j,bkj in enumerate(B[k]):
resi[j] += aik*bkj
resi[j] %= mod
return res
def matpow(A,p,mod):
if p%2:
return matmul(A, matpow(A,p-1,mod),mod)
elif p > 0:
b = matpow(A,p//2,mod)
return matmul(b,b,mod)
else:
return [[int(i==j) for j in range(len(A))] for i in range(len(A))]
a,b,n = map(int, input().split())
A = [[a,b],[1,0]]
B = matpow(A,n-1,mod1)
print(B[0][0]%mod1)
if __name__ == '__main__':
main()
buey_t