結果

問題 No.752 mod数列
ユーザー Ameesh SethiAmeesh Sethi
提出日時 2024-07-05 05:42:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 380 ms / 2,000 ms
コード長 496 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 82,288 KB
実行使用メモリ 79,416 KB
最終ジャッジ日時 2024-07-05 05:43:09
合計ジャッジ時間 9,269 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
59,008 KB
testcase_01 AC 41 ms
59,648 KB
testcase_02 AC 40 ms
59,392 KB
testcase_03 AC 35 ms
52,736 KB
testcase_04 AC 34 ms
52,480 KB
testcase_05 AC 39 ms
59,392 KB
testcase_06 AC 40 ms
59,136 KB
testcase_07 AC 40 ms
59,136 KB
testcase_08 AC 39 ms
59,368 KB
testcase_09 AC 39 ms
59,264 KB
testcase_10 AC 80 ms
74,880 KB
testcase_11 AC 77 ms
73,216 KB
testcase_12 AC 78 ms
74,368 KB
testcase_13 AC 78 ms
74,368 KB
testcase_14 AC 78 ms
74,880 KB
testcase_15 AC 309 ms
77,100 KB
testcase_16 AC 338 ms
79,056 KB
testcase_17 AC 380 ms
79,116 KB
testcase_18 AC 313 ms
77,328 KB
testcase_19 AC 334 ms
77,440 KB
testcase_20 AC 315 ms
77,312 KB
testcase_21 AC 321 ms
77,428 KB
testcase_22 AC 318 ms
77,056 KB
testcase_23 AC 339 ms
77,380 KB
testcase_24 AC 307 ms
77,080 KB
testcase_25 AC 189 ms
79,128 KB
testcase_26 AC 312 ms
79,104 KB
testcase_27 AC 259 ms
79,416 KB
testcase_28 AC 288 ms
79,124 KB
testcase_29 AC 363 ms
78,592 KB
testcase_30 AC 308 ms
79,096 KB
testcase_31 AC 34 ms
52,352 KB
testcase_32 AC 34 ms
52,352 KB
testcase_33 AC 42 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