結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー GER_chenGER_chen
提出日時 2021-01-22 22:37:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 879 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 10,852 KB
実行使用メモリ 12,728 KB
最終ジャッジ日時 2023-08-27 20:36:05
合計ジャッジ時間 8,601 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 218 ms
8,148 KB
testcase_01 AC 18 ms
8,056 KB
testcase_02 AC 16 ms
8,020 KB
testcase_03 AC 17 ms
7,980 KB
testcase_04 AC 17 ms
8,096 KB
testcase_05 AC 17 ms
7,992 KB
testcase_06 AC 294 ms
8,040 KB
testcase_07 AC 235 ms
7,964 KB
testcase_08 AC 810 ms
7,976 KB
testcase_09 TLE -
testcase_10 AC 765 ms
7,980 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#yuki-1358
from math import gcd
def num(a, b, s):
    g = gcd(a, b)
    if s%g:
        return 0
    if g > 1:
        return num(a//g, b//g, s//g)
    ini = s*pow(a, -1, b)%b
    return (s//a-ini)//b+1
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 += num(K, H, Y-i*N)
                ans %= mod
                i += g
            print(ans)
        else:
            i = 0
            while i*N <= Y:
                ans += num(K, H, Y-i*N)
                ans %= mod
                i += 1
            print(ans)
0