結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー GER_chenGER_chen
提出日時 2021-01-22 22:07:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 833 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 12,888 KB
最終ジャッジ日時 2023-08-27 19:21:57
合計ジャッジ時間 5,218 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
8,416 KB
testcase_01 AC 17 ms
8,280 KB
testcase_02 AC 17 ms
8,296 KB
testcase_03 AC 16 ms
8,416 KB
testcase_04 AC 17 ms
8,260 KB
testcase_05 AC 17 ms
8,404 KB
testcase_06 AC 84 ms
8,404 KB
testcase_07 AC 81 ms
8,316 KB
testcase_08 AC 205 ms
8,264 KB
testcase_09 AC 517 ms
8,348 KB
testcase_10 AC 184 ms
8,348 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def num(a, b, s):
    g = gcd(a, b)
    if s%g:
        return 0
    if g > 1:
        a //= g
        b //= g
        s //= g
    ini = s*pow(a, -1, b)%b
    return (s//a-ini)//b+1

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