結果

問題 No.2324 Two Countries within UEC
ユーザー navel_tos
提出日時 2023-05-29 17:33:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 492 ms / 2,000 ms
コード長 572 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 82,136 KB
実行使用メモリ 79,156 KB
最終ジャッジ日時 2024-06-26 23:33:41
合計ジャッジ時間 12,522 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#MMA Contest 015 C

'''
xが与えられるので、x*y mod P≡f となるyの個数を出力せよ。

急に緑diff。
絶対に初心者向けではない。難しすぎる。
'''
gcd=lambda x,y: gcd(y,x%y) if x%y else y
f=lambda:list(map(int,input().split()))

N,M,P,Q=f()
for _ in range(Q):
    x,a=f()
    if a>=P: print(0); continue
    Z=gcd(x,P)
    if a%Z: print(0); continue
    nX=x//Z; nP=P//Z; nA=a//Z
    revX=pow(nX,nP-2,nP)
    basic=revX*nA%nP
    ans=(M-basic)//nP-1
    while (ans+1)*nP<=M-basic: ans+=1
    if a==0: print(ans)
    else: print(ans+1)
0