結果
問題 |
No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
|
ユーザー |
![]() |
提出日時 | 2021-01-23 03:27:19 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 789 bytes |
コンパイル時間 | 320 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 124,416 KB |
最終ジャッジ日時 | 2024-12-29 13:33:00 |
合計ジャッジ時間 | 15,161 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 1 WA * 12 TLE * 4 |
ソースコード
import sys import io, os input = sys.stdin.buffer.readline t = int(input()) mod = 10**9+7 def extgcd(a, b): # ax+by = gcd(x, y)の整数解を求める # x, y, gcd(a, b)を返す if b == 0: return 1, 0, a q, r = divmod(a, b) x, y, d = extgcd(b, r) s, t = y, x-q*y return s, t, d import math for _ in range(t): n, k, h, y = map(int, input().split()) G = math.gcd(n, math.gcd(k, h)) if y%G: print(0) continue n, k, h, y = n//G, k//G, h//G, y//G a0, b0, g = extgcd(n, k) #print(a0, b0) ans = 0 for c in range(y//h+1): if (y-h*c)%g == 0: p = (y-h*c)//g cnt = (p*b0)//n-(-p*a0+k-1)//k+1 else: cnt = 0 ans += cnt ans %= mod print(ans)