結果

問題 No.1918 Simple Math ?
ユーザー tamatotamato
提出日時 2022-04-29 23:44:33
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 904 bytes
コンパイル時間 467 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 81,904 KB
最終ジャッジ日時 2023-09-11 15:25:05
合計ジャッジ時間 5,208 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 181 ms
76,984 KB
testcase_01 AC 89 ms
77,068 KB
testcase_02 AC 91 ms
77,272 KB
testcase_03 AC 89 ms
77,132 KB
testcase_04 AC 91 ms
77,224 KB
testcase_05 AC 90 ms
77,248 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 #

mod = 1000000007


def main():
    import sys
    from math import floor, sqrt
    input = sys.stdin.readline

    def floor_sqrt(a):
        x0 = floor(sqrt(a))
        res = 0
        for x in range(x0 - 1, x0 + 2):
            if x <= 0:
                continue
            if x ** 2 <= a:
                res = max(res, x)
        return res

    for _ in range(int(input())):
        a, N = map(int, input().split())
        ans = prev = floor_sqrt(a)
        n = 1
        while n < N:
            n_new = ((prev + 1) ** 2 - 1) // a + 1
            val = floor_sqrt(a * n_new)
            assert val ** 2 <= a * n_new < (val + 1) ** 2
            if n_new <= N:
                ans += val + (n_new - n - 1) * prev
            else:
                ans += prev * (N - n)
            ans %= mod
            n = n_new
            prev = val
        print(ans)


if __name__ == '__main__':
    main()
0