結果

問題 No.2128 Round up!!
ユーザー miscalcmiscalc
提出日時 2022-11-18 23:20:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 345 ms / 2,000 ms
コード長 526 bytes
コンパイル時間 1,912 ms
コンパイル使用メモリ 81,172 KB
実行使用メモリ 77,928 KB
最終ジャッジ日時 2023-10-20 08:22:51
合計ジャッジ時間 5,358 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,312 KB
testcase_01 AC 300 ms
77,928 KB
testcase_02 AC 40 ms
53,316 KB
testcase_03 AC 216 ms
76,876 KB
testcase_04 AC 227 ms
76,920 KB
testcase_05 AC 236 ms
76,900 KB
testcase_06 AC 251 ms
76,612 KB
testcase_07 AC 285 ms
76,756 KB
testcase_08 AC 284 ms
76,752 KB
testcase_09 AC 214 ms
76,872 KB
testcase_10 AC 345 ms
77,456 KB
testcase_11 AC 344 ms
77,456 KB
testcase_12 AC 288 ms
77,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def divceil(a, b):
  return (a + b - 1) // b
def solve(x, a, b):
  a, b = min(a, b), max(a, b)
  g = math.gcd(a, b)
  k = a // g
  x %= a * b // g
  if x == 0:
    return 1
  n, m = divceil(x, a), divceil(x, b)
  if a == 1 or a == b:
    return 1 if x == m * b else 2
  ans = 0
  if not(x == n * a or x == m * b):
    ans += 1
  if not(n * a < m * b):
    ans -= 1
  ans += 2 * (k - m + 1)
  return ans

t = int(input())
for _ in range(t):
  x, a, b = map(int, input().split())
  print(solve(x, a, b) % 998244353)
0