結果

問題 No.1648 Sum of Powers
ユーザー convexineqconvexineq
提出日時 2021-08-13 22:53:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 518 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 82,336 KB
実行使用メモリ 101,416 KB
最終ジャッジ日時 2024-10-03 21:40:18
合計ジャッジ時間 8,082 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 53 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353
a,b,p,q = map(int,input().split())

T = 10**5+9
memo = {}
f = lambda x,y: (y,(a*y-b*x)%MOD)
B = (q,p)
for i in range(T):
    memo[B] = i
    B = f(*B)

s = (2,a)
for i in range(T):
    if s == (q,p):
        print(i+2)
        exit()
    s = f(*s)

v,w = (1,0),(0,1)
for _ in range(T):
    v,w = f(*v),f(*w)
c1,c2 = v
c3,c4 = w
g = lambda x,y: ((c1*x+c3*y)%MOD,(c2*x+c4*y)%MOD)

s = (2,a)
for j in range(1,T+1):
    s = g(*s)
    if s in memo:
        i = memo[s]
        print(j*T-i+1)
        exit()
0