結果

問題 No.2128 Round up!!
ユーザー とりゐとりゐ
提出日時 2022-11-18 21:52:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 494 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 81,712 KB
実行使用メモリ 76,768 KB
最終ジャッジ日時 2023-10-20 06:42:32
合計ジャッジ時間 3,323 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,700 KB
testcase_01 AC 146 ms
76,768 KB
testcase_02 AC 38 ms
53,700 KB
testcase_03 AC 107 ms
76,304 KB
testcase_04 AC 120 ms
76,256 KB
testcase_05 AC 126 ms
76,368 KB
testcase_06 AC 138 ms
76,048 KB
testcase_07 AC 176 ms
76,400 KB
testcase_08 AC 173 ms
76,368 KB
testcase_09 AC 107 ms
76,516 KB
testcase_10 AC 195 ms
76,732 KB
testcase_11 AC 195 ms
76,644 KB
testcase_12 AC 145 ms
75,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
input=lambda :stdin.readline()[:-1]
from math import gcd
mod=998244353
def lcm(x,y):
  return x//gcd(x,y)*y

def solve():
  x,a,b=map(int,input().split())
  L=lcm(a,b)
  x-=(x-1)//L*L
  if x==L:
    print(1)
    return
  if a==b:
    print(2)
    return
  
  a,b=min(a,b),max(a,b)
  
  y=(L-x)//b
  ans=2*y+1
  nxt_a=(x+a-1)//a*a
  nxt_b=(x+b-1)//b*b
  if nxt_a<nxt_b:
    ans+=1
  if x%a!=0 and x%b!=0:
    ans+=1
  print(ans%mod)

for _ in range(int(input())):
  solve()
0