結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー GER_chen
提出日時 2021-01-22 22:33:26
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 748 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 21,760 KB
最終ジャッジ日時 2024-12-28 03:15:10
合計ジャッジ時間 22,583 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 WA * 8 TLE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#yuki-1358
from math import gcd
mod = 10**9+7
T = int(input())  #20以下

#testcases
for _ in range(T):
    N, K, H, Y = map(int, input().split())
    g = gcd(K, H)
    h = gcd(N, g)
    if Y%h:
        print(0)
    else:
        if h-1:
            N, K, H, Y, g = N//h, K//h, H//h, Y//h, g//h
        rev = pow(K//g,-1, H//g)
        ans = 0
        if g-1:
            i = Y*pow(N, -1, g)%g
            while N*i <= Y:
                ans += ((Y-i*N)//K-(rev*(Y-i*N))//h%(H//h))//H+1
                ans %= mod
                i += g
            print(ans)
        else:
            i = 0
            while i*N <= Y:
                ans += ((Y-i*N)//K-rev*(Y-i*N)%H)//H+1
                ans %= mod
                i += 1
            print(ans)
0