結果

問題 No.752 mod数列
ユーザー convexineqconvexineq
提出日時 2021-05-22 19:19:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 426 ms / 2,000 ms
コード長 496 bytes
コンパイル時間 822 ms
コンパイル使用メモリ 82,944 KB
実行使用メモリ 79,616 KB
最終ジャッジ日時 2024-04-19 00:57:19
合計ジャッジ時間 10,519 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
59,136 KB
testcase_01 AC 48 ms
59,648 KB
testcase_02 AC 48 ms
59,392 KB
testcase_03 AC 41 ms
52,864 KB
testcase_04 AC 41 ms
52,608 KB
testcase_05 AC 46 ms
59,264 KB
testcase_06 AC 48 ms
59,520 KB
testcase_07 AC 48 ms
59,648 KB
testcase_08 AC 48 ms
59,392 KB
testcase_09 AC 49 ms
59,520 KB
testcase_10 AC 93 ms
74,880 KB
testcase_11 AC 91 ms
73,600 KB
testcase_12 AC 100 ms
74,240 KB
testcase_13 AC 91 ms
73,728 KB
testcase_14 AC 95 ms
75,008 KB
testcase_15 AC 370 ms
77,184 KB
testcase_16 AC 420 ms
79,200 KB
testcase_17 AC 426 ms
79,280 KB
testcase_18 AC 380 ms
77,440 KB
testcase_19 AC 394 ms
77,440 KB
testcase_20 AC 362 ms
77,568 KB
testcase_21 AC 353 ms
77,184 KB
testcase_22 AC 399 ms
77,312 KB
testcase_23 AC 376 ms
77,312 KB
testcase_24 AC 376 ms
77,184 KB
testcase_25 AC 200 ms
79,184 KB
testcase_26 AC 362 ms
79,028 KB
testcase_27 AC 297 ms
79,616 KB
testcase_28 AC 347 ms
79,324 KB
testcase_29 AC 401 ms
78,592 KB
testcase_30 AC 361 ms
78,720 KB
testcase_31 AC 38 ms
52,608 KB
testcase_32 AC 41 ms
52,480 KB
testcase_33 AC 51 ms
61,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_right

def f(r):
    i = bisect_right(R,r)-1
    res = r*p - acc[i]
    r = min(r,p)
    res -= (r+R[i]+1)*(r-R[i])//2*V[i]
    return res

p,Q = map(int,input().split())
M = int(p**0.5)
V = [p//i for i in range(1,M)] + list(range(1,p//M+1)[::-1])
R = [0]+[p//i for i in V]
V += [0]
acc = [0]*(len(V)+1)
for i in range(1,len(V)):
    acc[i] = acc[i-1] + (R[i]+R[i-1]+1)*(R[i]-R[i-1])//2*V[i-1]
for _ in range(Q):
    l,r = map(int,input().split())
    print(f(r)-f(l-1))
0