問題一覧 > 通常問題

No.752 Mod Sequence

レベル : / AI推定難易度 : 1525 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 61
作問者 : %20 / テスター : nmnmnmnmnmnmnm
お気に入りにしたユーザー ProblemId : 2158 / 自分の提出
問題文最終更新日: 2026-06-25 08:02:31
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 203 (順位表) の他の問題:

Problem Statement

Let $a_n=P\bmod n\ (n=1,2,\dots)$.
For each given $L_i,R_i\ (i=1,2,\dots,Q)$, find the value of $\displaystyle\sum_{n=L_i}^{R_i}a_n$.

Input

$P$ $Q$
$L_1$ $R_1$
$L_2$ $R_2$
$\vdots$
$L_Q$ $R_Q$

The input satisfies the following constraints.

  • $1\le P\le10^9$
  • $1\le Q\le10^5$
  • $1\le L_i\le R_i\le 10^9$
  • All input values are integers.

Output

$\sum_{n=L_1}^{R_1}a_n$
$\sum_{n=L_2}^{R_2}a_n$
$\vdots$
$\sum_{n=L_Q}^{R_Q}a_n$

Print $Q$ lines, where the $i$-th line contains the value of $\sum_{n=L_i}^{R_i}a_n$.

Sample

Sample 1
Input
23 1
1 7
Output
16

We have $\sum_{n=1}^7a_n=0+1+2+3+3+5+2=16$.

Sample 2
Input
3000 4
7 36
1 2491
2934 3000
1542 5231
Output
263
1465544
2211
7756611

It is possible that $P\lt R_i$.

Sample 3
Input
319586423 10
88 861
4641915 12591875
40 93620
4 58503
41376643 99181970
8388 351105
4029987 4171876
184091372 270441885
45972 65554518
8313 52186
Output
180038
34469822716416
2189413228
855085983
2015105445915363
30802594433
294723880788
7971861707449373
1053080394476134
663106681

The answer may be greater than $2^{32}$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。