結果

問題 No.1918 Simple Math ?
ユーザー tassei903tassei903
提出日時 2022-04-29 23:49:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 639 ms / 2,000 ms
コード長 883 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 76,740 KB
最終ジャッジ日時 2023-09-11 15:32:25
合計ジャッジ時間 11,115 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
75,876 KB
testcase_01 AC 90 ms
76,460 KB
testcase_02 AC 92 ms
76,592 KB
testcase_03 AC 89 ms
76,492 KB
testcase_04 AC 91 ms
76,580 KB
testcase_05 AC 90 ms
76,556 KB
testcase_06 AC 137 ms
75,868 KB
testcase_07 AC 173 ms
76,740 KB
testcase_08 AC 122 ms
75,776 KB
testcase_09 AC 104 ms
75,888 KB
testcase_10 AC 136 ms
75,988 KB
testcase_11 AC 82 ms
75,976 KB
testcase_12 AC 160 ms
76,532 KB
testcase_13 AC 136 ms
76,268 KB
testcase_14 AC 114 ms
75,824 KB
testcase_15 AC 95 ms
75,956 KB
testcase_16 AC 326 ms
76,580 KB
testcase_17 AC 341 ms
76,520 KB
testcase_18 AC 434 ms
76,556 KB
testcase_19 AC 456 ms
76,588 KB
testcase_20 AC 393 ms
76,584 KB
testcase_21 AC 610 ms
76,492 KB
testcase_22 AC 607 ms
76,684 KB
testcase_23 AC 602 ms
76,568 KB
testcase_24 AC 604 ms
76,492 KB
testcase_25 AC 607 ms
76,520 KB
testcase_26 AC 634 ms
76,596 KB
testcase_27 AC 639 ms
76,456 KB
testcase_28 AC 411 ms
76,500 KB
testcase_29 AC 72 ms
71,332 KB
testcase_30 AC 73 ms
71,532 KB
testcase_31 AC 634 ms
76,500 KB
testcase_32 AC 83 ms
76,004 KB
testcase_33 AC 82 ms
75,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10**9+7

def sqrt(x):
    ok = 0
    ng = 10**9+1
    while ng - ok > 1:
        d = (ok+ng)>>1
        if d * d <= x:
            ok = d
        else:
            ng = d
    return ok
def f(a, n):
    ans = 0
    for k in range(1,sqrt(a*n)+1):
        ans += n+1-(k*k+a-1)//a
        #print(n+1-(k*k+a-1)//a)
        ans %= mod
    return ans
def g(a, n):
    N = sqrt(a*n)
    ans = (n+1)*N
    for b in range(a):
        r = (N+b)//a
        l = b//a
        #print(l, r)
        ans -= (b*b+a-1)//a * (r - l)
        ans %= mod
        ans -= a * (r*(r+1)*(2*r+1)//6)
        ans %= mod
        ans += a * (l*(l+1)*(2*l+1)//6)
        ans %= mod
        ans += b*(r*(r+1))
        ans %= mod
        ans -= b*(l*(l+1))
        ans %= mod

    return ans

for _ in range(int(input())):
    a,n = map(int,input().split())
    #ans1 = f(a, n)
    ans = g(a, n)
    print(ans)
0