結果

問題 No.1918 Simple Math ?
ユーザー tktk_snsntktk_snsn
提出日時 2022-04-29 23:58:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,125 bytes
コンパイル時間 1,231 ms
コンパイル使用メモリ 86,732 KB
実行使用メモリ 82,388 KB
最終ジャッジ日時 2023-09-11 15:44:03
合計ジャッジ時間 6,532 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 108 ms
76,744 KB
testcase_02 AC 111 ms
76,668 KB
testcase_03 AC 110 ms
76,956 KB
testcase_04 AC 116 ms
77,240 KB
testcase_05 AC 120 ms
77,080 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def F(x):
    res = int(x ** 0.5)
    for i in range(-2, 3)[::-1]:
        if (res + i) * (res + i) <= x:
            return res + i


def naive(a, N):
    res = 0
    for i in range(1, N+1):
        print(i, F(a * i))
        res += F(a * i)
    return res


def ub(a, target):
    l = 0
    r = 10 ** 18
    while r - l > 1:
        m = (r + l) // 2
        if a * m < target * target:
            l = m
        else:
            r = m
    return r


def lb(a, target):
    l = 0
    r = 10 ** 18
    while r - l > 1:
        m = (r + l) // 2
        if a * m < target * target:
            l = m
        else:
            r = m
    return r


T = int(input())
for _ in range(T):
    a, N = map(int, input().split())
    sq = int(N ** 0.5 + 1)

    lim = F(a * sq)

    ans = 0
    for i in range(1, N + 1):
        tmp = F(a * i)
        if tmp >= lim:
            key = i
            break
        ans += tmp

    L = lim
    R = F(a * N)
    p = lb(a, L)
    for k in range(L, R+1):
        q = ub(a, k + 1)
        q = min(N + 1, q)
        ans += k * (q - p)
        p = q
    # print(ans, naive(a, N))
    print(ans)
0