結果
| 問題 | No.1049 Zero (Exhaust) | 
| コンテスト | |
| ユーザー |  buey_t | 
| 提出日時 | 2023-03-21 15:25:43 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 139 ms / 2,000 ms | 
| コード長 | 1,686 bytes | 
| コンパイル時間 | 291 ms | 
| コンパイル使用メモリ | 81,744 KB | 
| 実行使用メモリ | 85,140 KB | 
| 最終ジャッジ日時 | 2024-09-18 14:23:13 | 
| 合計ジャッジ時間 | 4,545 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 22 | 
ソースコード
def main():
    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))]
    
    P,K = map(int, input().split())
    
    A = [[P+1,2*(P-1)],[1,2*(P-1)]]
    
    ls = matpow(A,K,mod1)
    
    print(ls[0][0])
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
if __name__ == '__main__':
    main()
            
            
            
        