結果

問題 No.2078 魔抜けなパープル
ユーザー ああいいああいい
提出日時 2022-09-28 09:33:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 550 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 87,144 KB
実行使用メモリ 71,456 KB
最終ジャッジ日時 2023-08-24 04:16:58
合計ジャッジ時間 1,586 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,392 KB
testcase_01 AC 72 ms
71,352 KB
testcase_02 AC 73 ms
71,440 KB
testcase_03 AC 74 ms
71,456 KB
testcase_04 AC 73 ms
71,432 KB
testcase_05 AC 71 ms
71,292 KB
testcase_06 AC 72 ms
71,424 KB
testcase_07 AC 74 ms
71,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())

def calc(x,a):
    low = 1
    high = a
    while low + 2 < high:
        b = (low * 2 + high) // 3
        c = (low + high * 2) // 3
        if f(b,x,a) < f(c,x,a):
            high = c
        else:
            low = b
    ans = 10 ** 30
    for i in range(low,high + 1):
        if f(i,x,a) < ans:
            ans = f(i,x,a)
    return ans

def f(n,x,a):
    q = a // n
    r = a % n
    ans = n * x + (q + 1) ** 2 * r + q ** 2 * (n - r)
    return ans

for _ in range(T):
    x,a = map(int,input().split())
    print(calc(x,a))
0