結果

問題 No.752 mod数列
ユーザー maspymaspy
提出日時 2020-01-22 21:48:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 384 ms / 2,000 ms
コード長 957 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 10,956 KB
実行使用メモリ 44,304 KB
最終ジャッジ日時 2023-09-23 02:15:55
合計ジャッジ時間 11,468 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
31,680 KB
testcase_01 AC 132 ms
31,604 KB
testcase_02 AC 130 ms
31,344 KB
testcase_03 AC 131 ms
31,284 KB
testcase_04 AC 131 ms
31,124 KB
testcase_05 AC 132 ms
31,540 KB
testcase_06 AC 131 ms
31,368 KB
testcase_07 AC 128 ms
31,596 KB
testcase_08 AC 129 ms
31,708 KB
testcase_09 AC 133 ms
31,616 KB
testcase_10 AC 137 ms
32,500 KB
testcase_11 AC 136 ms
32,072 KB
testcase_12 AC 136 ms
32,692 KB
testcase_13 AC 133 ms
32,312 KB
testcase_14 AC 136 ms
32,656 KB
testcase_15 AC 348 ms
41,896 KB
testcase_16 AC 288 ms
44,024 KB
testcase_17 AC 338 ms
44,304 KB
testcase_18 AC 367 ms
42,564 KB
testcase_19 AC 338 ms
43,032 KB
testcase_20 AC 377 ms
43,136 KB
testcase_21 AC 383 ms
43,088 KB
testcase_22 AC 384 ms
42,912 KB
testcase_23 AC 350 ms
43,044 KB
testcase_24 AC 350 ms
43,040 KB
testcase_25 AC 198 ms
35,936 KB
testcase_26 AC 306 ms
40,936 KB
testcase_27 AC 251 ms
38,516 KB
testcase_28 AC 291 ms
40,272 KB
testcase_29 AC 303 ms
43,024 KB
testcase_30 AC 314 ms
43,432 KB
testcase_31 AC 127 ms
31,192 KB
testcase_32 AC 128 ms
31,104 KB
testcase_33 AC 130 ms
32,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

P,Q = map(int, readline().split())
m = map(int,read().split())
LR = zip(m,m)

M = 30000
low_max = P//(M+1)
if low_max < 0:
    low_max = 0

lower = np.cumsum(P % np.arange(low_max + 1, dtype=np.int64))

left = P // np.arange(1, M+2, dtype=np.int64)
right = P // np.arange(0, M+1, dtype=np.int64)
S = (right - left) * (right + left + 1) // 2

upper = P * (right - left) - np.arange(M+1, dtype=np.int64) * S
upper[0] = 0
upper = upper[::-1].cumsum()[::-1]

lower = lower.tolist()
upper = upper.tolist()
upper.append(0)

def F(N):
    if N <= low_max:
        return lower[N]
    if N > P:
        return upper[0] + lower[-1] + (N - P) * P
    n = P // N
    x = lower[-1] + upper[n+1]  # 商 n+1 以上
    L = P // (n+1)
    return x + P * (N - L) - (N - L) * (N + L + 1) // 2 * n

for L,R in LR:
    print(F(R) - F(L-1))
0