結果

問題 No.1899 L1 Cafe
ユーザー chineristACchineristAC
提出日時 2022-04-08 23:09:41
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 425 ms / 2,000 ms
コード長 1,038 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 87,284 KB
実行使用メモリ 86,696 KB
最終ジャッジ日時 2023-08-19 01:44:18
合計ジャッジ時間 5,992 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
74,804 KB
testcase_01 AC 407 ms
86,188 KB
testcase_02 AC 327 ms
84,148 KB
testcase_03 AC 291 ms
84,424 KB
testcase_04 AC 310 ms
85,404 KB
testcase_05 AC 276 ms
84,688 KB
testcase_06 AC 425 ms
85,812 KB
testcase_07 AC 333 ms
86,304 KB
testcase_08 AC 348 ms
85,896 KB
testcase_09 AC 245 ms
83,480 KB
testcase_10 AC 346 ms
86,012 KB
testcase_11 AC 256 ms
82,944 KB
testcase_12 AC 415 ms
86,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import log,gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

def floor_sum(n: int, m: int, a: int, b: int) -> int:
    ans = 0

    if a >= m:
        ans += (n - 1) * n * (a // m) // 2
        a %= m

    if b >= m:
        ans += n * (b // m)
        b %= m

    y_max = (a * n + b) // m
    x_max = y_max * m - b

    if y_max == 0:
        return ans

    ans += (n - (x_max + a - 1) // a) * y_max
    ans += floor_sum(y_max, a, m, (a - x_max % a) % a)

    return ans

for _ in range(int(input())):
    N,A,B = mi()

    tmp = 0

    k = N//A
    tmp += N * k - A * k*(k+1)//2
    k = N//B
    tmp += N * k - B * k*(k+1)//2

    k = N//A
    m = (A+B-1)//B
    double = floor_sum(k+1,B,B*m-A,N) - (N//B) - m * k*(k+1)//2
    tmp -= double

    #print(tmp,double)

    res = 4 * N + 1 + 4 * tmp
    print(tmp)
    
0