結果

問題 No.1899 L1 Cafe
ユーザー mkawa2mkawa2
提出日時 2023-12-13 12:18:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 235 ms / 2,000 ms
コード長 1,493 bytes
コンパイル時間 408 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 77,584 KB
最終ジャッジ日時 2023-12-13 12:18:57
合計ジャッジ時間 6,038 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 233 ms
77,416 KB
testcase_02 AC 226 ms
77,188 KB
testcase_03 AC 172 ms
77,328 KB
testcase_04 AC 182 ms
76,792 KB
testcase_05 AC 150 ms
77,332 KB
testcase_06 AC 235 ms
77,300 KB
testcase_07 AC 215 ms
77,552 KB
testcase_08 AC 209 ms
77,192 KB
testcase_09 AC 189 ms
77,584 KB
testcase_10 AC 212 ms
77,160 KB
testcase_11 AC 219 ms
77,512 KB
testcase_12 AC 234 ms
77,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(1000005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 62)

# md = 10**9+7
md = 998244353

def floor_sum(n, m, a, b):
    ans = 0
    if a < 0:
        ans += n*(n-1)*(a//m)//2
        a %= m
    if b < 0:
        ans += n*(b//m)
        b %= m
    while True:
        if a >= m:
            ans += n*(n-1)*(a//m)//2
            a %= m
        if b >= m:
            ans += n*(b//m)
            b %= m
        y_max = a*n+b
        if y_max < m: break
        n, b, m, a, = y_max//m, y_max%m, a, m

    return ans

# y=-x+N
# y=-An+N
# y=(-An+N)/1

# y=-x+N
# Bm=-x+N
# m=(-x+N)/B

# y=-x+N
# Bm=-An+N
# m=(-An+N)/B

def solve():
    N, A, B = LI()
    ans = floor_sum((N+A-1)//A, 1, -A, N)
    ans += floor_sum(N, B, -1, N)
    ans -= floor_sum((N+A-1)//A, B, -A, N)
    print(ans-N)

for _ in range(II()): solve()
0