結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-02-13 20:23:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,049 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 12,720 KB
最終ジャッジ日時 2023-09-28 05:46:30
合計ジャッジ時間 5,083 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
12,580 KB
testcase_01 AC 15 ms
8,176 KB
testcase_02 AC 16 ms
7,960 KB
testcase_03 AC 15 ms
8,232 KB
testcase_04 AC 15 ms
8,288 KB
testcase_05 AC 15 ms
8,296 KB
testcase_06 AC 128 ms
8,212 KB
testcase_07 AC 95 ms
8,208 KB
testcase_08 AC 99 ms
8,240 KB
testcase_09 AC 94 ms
8,292 KB
testcase_10 AC 79 ms
8,172 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=10**9+7
def gcd(a,b):
  while b:a,b=b,a%b
  return a
def main1(n,k,h,y):
  ary=[n,k,h]
  ary.sort()
  a,b,c=ary
  g=gcd(a,b)
  na,nb=a//g,b//g
  now=0
  ans=0
  while now<=y:
    yy=y-now
    now+=c
    if yy%g!=0:continue
    yy=yy//g
    if yy==0:
      ans+=1
      continue
    if yy<na:continue
    if yy<nb:
      if yy%na==0:
        ans+=1
      continue
    # yy-nb*iがmod naで0になるiの個数
    # yy%na=nb*i%na となるiの個数
    # 0<=i<=yy//nb
    # yy%na=nb*i%na となる最小のiを求める。あとは周期naで循環する。
    u=yy%na
    v=nb%na
    # u=v*i
    # u*v^(-1)=i
    if u==0:
      i=0
    elif u==v:
      i=1
    else:
      i=u*pow(v,-1,na)
      i%=na
    #print((na,nb),yy,i)
    if yy-nb*i<0:continue
    w=yy//nb
    if i<=w:
      ans+=(w-i)//na+1
      ans%=mod
      #print((u,v,w))
      #print((na,nb,yy),i,w,(w-i)//na+1)
  return ans
if __name__=='__main__':
  t=int(input())
  cases=[list(map(int,input().split())) for _ in range(t)]
  for n,k,h,y in cases:
    print(main1(n,k,h,y))
0