結果

問題 No.2128 Round up!!
ユーザー 👑 rin204rin204
提出日時 2022-11-18 21:53:20
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 290 ms / 2,000 ms
コード長 569 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 81,796 KB
実行使用メモリ 77,672 KB
最終ジャッジ日時 2023-10-20 06:43:29
合計ジャッジ時間 4,691 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,612 KB
testcase_01 AC 235 ms
77,672 KB
testcase_02 AC 34 ms
53,612 KB
testcase_03 AC 224 ms
77,344 KB
testcase_04 AC 230 ms
77,356 KB
testcase_05 AC 237 ms
77,304 KB
testcase_06 AC 262 ms
77,072 KB
testcase_07 AC 290 ms
77,140 KB
testcase_08 AC 286 ms
77,140 KB
testcase_09 AC 214 ms
77,336 KB
testcase_10 AC 285 ms
77,316 KB
testcase_11 AC 285 ms
77,316 KB
testcase_12 AC 263 ms
77,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
MOD = 998244353

def solve(x, a, b):
    l = a // gcd(a, b) * b
    ma = (x + l - 1) // l * l
    if ma == x:
        return 1
    d = ma - x - 1
    aa = d // a
    bb = d // b
    a_ = (x + a) // a * a
    b_ = (x + b) // b * b
    ret = 2 + min(aa, bb) * 2
    
    if aa == bb:
        pass
    elif a < b:
        if a_ < b_ and x % a != 0:
            ret += 1
    else:
        if b_ < a_ and x % b != 0:
            ret += 1
    return ret
    

for _ in range(int(input())):
    ans = solve(*map(int, input().split()))
    print(ans % MOD)
0