結果

問題 No.752 mod数列
ユーザー maspymaspy
提出日時 2020-01-22 21:36:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 964 bytes
コンパイル時間 69 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 44,264 KB
最終ジャッジ日時 2023-09-23 01:54:23
合計ジャッジ時間 13,566 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
31,556 KB
testcase_01 AC 127 ms
31,572 KB
testcase_02 AC 127 ms
31,276 KB
testcase_03 AC 128 ms
31,292 KB
testcase_04 AC 129 ms
31,200 KB
testcase_05 AC 128 ms
31,532 KB
testcase_06 AC 128 ms
31,464 KB
testcase_07 AC 130 ms
31,636 KB
testcase_08 AC 128 ms
31,612 KB
testcase_09 AC 127 ms
31,588 KB
testcase_10 AC 132 ms
32,688 KB
testcase_11 AC 130 ms
32,188 KB
testcase_12 AC 131 ms
32,620 KB
testcase_13 AC 131 ms
32,516 KB
testcase_14 AC 131 ms
32,644 KB
testcase_15 AC 340 ms
41,872 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 364 ms
42,404 KB
testcase_19 AC 335 ms
43,116 KB
testcase_20 AC 382 ms
43,044 KB
testcase_21 AC 376 ms
43,016 KB
testcase_22 AC 378 ms
42,772 KB
testcase_23 AC 347 ms
43,076 KB
testcase_24 AC 347 ms
42,820 KB
testcase_25 AC 197 ms
35,980 KB
testcase_26 WA -
testcase_27 AC 248 ms
38,432 KB
testcase_28 WA -
testcase_29 AC 297 ms
43,072 KB
testcase_30 AC 311 ms
43,352 KB
testcase_31 AC 128 ms
31,004 KB
testcase_32 AC 125 ms
31,148 KB
testcase_33 AC 130 ms
32,452 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)//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