結果
| 問題 |
No.752 mod数列
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:20:46 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,235 bytes |
| コンパイル時間 | 167 ms |
| コンパイル使用メモリ | 82,512 KB |
| 実行使用メモリ | 107,504 KB |
| 最終ジャッジ日時 | 2025-03-20 20:22:21 |
| 合計ジャッジ時間 | 5,675 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 16 TLE * 1 -- * 14 |
ソースコード
import sys
def main():
input = sys.stdin.read().split()
idx = 0
P = int(input[idx])
idx += 1
Q = int(input[idx])
idx += 1
queries = []
for _ in range(Q):
L = int(input[idx])
R = int(input[idx + 1])
queries.append((L, R))
idx += 2
results = []
for L, R in queries:
# Adjust the range to [1, P]
adjusted_L = max(L, 1)
adjusted_R = min(R, P)
sum_part1 = 0
if adjusted_L <= adjusted_R:
a, b = adjusted_L, adjusted_R
total = 0
l = a
while l <= b:
k = P // l
r = P // k
if r > b:
r = b
cnt = r - l + 1
sum_n = (l + r) * cnt // 2
contribution = k * sum_n
total += contribution
l = r + 1
sum_part1 = P * (b - a + 1) - total
sum_part2 = 0
if R > P:
left = max(L, P + 1)
if left <= R:
sum_part2 = P * (R - left + 1)
results.append(sum_part1 + sum_part2)
print('\n'.join(map(str, results)))
if __name__ == '__main__':
main()
lam6er