結果

問題 No.752 mod数列
ユーザー square1001square1001
提出日時 2018-11-09 22:18:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 422 ms / 2,000 ms
コード長 724 bytes
コンパイル時間 610 ms
コンパイル使用メモリ 69,364 KB
実行使用メモリ 81,764 KB
最終ジャッジ日時 2024-05-01 04:57:33
合計ジャッジ時間 8,088 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
81,536 KB
testcase_01 AC 48 ms
81,740 KB
testcase_02 AC 49 ms
81,440 KB
testcase_03 AC 48 ms
81,560 KB
testcase_04 AC 48 ms
81,612 KB
testcase_05 AC 48 ms
81,468 KB
testcase_06 AC 48 ms
81,588 KB
testcase_07 AC 48 ms
81,584 KB
testcase_08 AC 47 ms
81,764 KB
testcase_09 AC 48 ms
81,544 KB
testcase_10 AC 51 ms
81,540 KB
testcase_11 AC 52 ms
81,572 KB
testcase_12 AC 52 ms
81,588 KB
testcase_13 AC 53 ms
81,584 KB
testcase_14 AC 51 ms
81,596 KB
testcase_15 AC 215 ms
81,580 KB
testcase_16 AC 226 ms
81,564 KB
testcase_17 AC 363 ms
81,688 KB
testcase_18 AC 240 ms
81,536 KB
testcase_19 AC 304 ms
81,544 KB
testcase_20 AC 263 ms
81,672 KB
testcase_21 AC 257 ms
81,496 KB
testcase_22 AC 258 ms
81,620 KB
testcase_23 AC 329 ms
81,564 KB
testcase_24 AC 322 ms
81,420 KB
testcase_25 AC 162 ms
81,564 KB
testcase_26 AC 301 ms
81,640 KB
testcase_27 AC 223 ms
81,640 KB
testcase_28 AC 279 ms
81,592 KB
testcase_29 AC 312 ms
81,656 KB
testcase_30 AC 422 ms
81,584 KB
testcase_31 AC 45 ms
81,536 KB
testcase_32 AC 46 ms
81,532 KB
testcase_33 AC 47 ms
81,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int P, Q, L, R; long long s[10000009];
long long solve(int x) {
	if (x <= 10000000) return s[x + 1];
	long long ret = s[10000001];
	for (int i = 1; i <= 100; ++i) {
		int l = P / (i + 1), r = P / i;
		if (r <= 10000000 || l >= x) continue;
		l = max(l, 10000000);
		r = min(r, x);
		ret += 1LL * (P % r) * (r - l) + 1LL * i * (r - l) * (r - l - 1) / 2;
	}
	if (P < x && x > 10000000) ret += 1LL * (x - max(P, 10000000)) * P;
	return ret;
}
int main() {
	cin >> P >> Q;
	for (int i = 1; i <= 10000000; ++i) {
		s[i + 1] = s[i] + P % i;
	}
	for (int i = 0; i < Q; ++i) {
		cin >> L >> R;
		cout << solve(R) - solve(L - 1) << '\n';
	}
	return 0;
}
0