結果

問題 No.980 Fibonacci Convolution Hard
ユーザー convexineqconvexineq
提出日時 2020-01-31 22:33:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 319 ms / 2,000 ms
コード長 1,073 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 81,544 KB
実行使用メモリ 128,372 KB
最終ジャッジ日時 2023-10-17 13:41:34
合計ジャッジ時間 8,545 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 305 ms
128,276 KB
testcase_01 AC 305 ms
128,276 KB
testcase_02 AC 309 ms
128,276 KB
testcase_03 AC 310 ms
128,276 KB
testcase_04 AC 299 ms
128,276 KB
testcase_05 AC 315 ms
128,276 KB
testcase_06 AC 306 ms
128,344 KB
testcase_07 AC 311 ms
128,344 KB
testcase_08 AC 310 ms
128,276 KB
testcase_09 AC 313 ms
128,276 KB
testcase_10 AC 313 ms
128,292 KB
testcase_11 AC 319 ms
128,292 KB
testcase_12 AC 310 ms
128,360 KB
testcase_13 AC 311 ms
128,372 KB
testcase_14 AC 313 ms
128,372 KB
testcase_15 AC 310 ms
128,308 KB
testcase_16 AC 281 ms
127,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""
def extgcd(x,y):
    if y==0: return 1,0 #g=x
    r0,r1,s0,s1 = x,y,1,0
    while r1 != 0:
        r0,r1, s0,s1 = r1,r0%r1, s1,s0-r0//r1*s1
    #g = r0
    return s0,(r0-s0*x)//y
    
def modinv(a,MOD):
    x,y = extgcd(a,MOD)
    return x%MOD
"""

# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

def poly_inverse(f,n):
    g = [0]*(n+1)
    df = len(f)
    g[0] = pow(f[0],MOD-2,MOD)
    for i in range(1,n):
        for j in range(1,df):
            if i+j-2 >= n: break
            g[i+j-1] += g[i-1]*f[j]
            g[i+j-1] %= MOD
        g[i] = -g[0]*g[i]%MOD
    return g            
    
def poly_product(f,g):
    df = len(f)
    dg = len(g)
    res = [0]*(df+dg-1)
    for i in range(df):
        for j in range(dg):
            res[i+j] += f[i]*g[j]
            res[i+j] %= MOD
    return res

p,Q,*q = map(int,read().split())
MOD = 1000000007

MAX = 2*(10**6)
f = [1,(-2*p)%MOD,(p*p-2)%MOD,2*p%MOD,1]
ans = [0]*4+poly_inverse(f,MAX)

#print(ans)
#print(poly_product(f,ans))

for i in q:
    print(ans[i])

0