結果

問題 No.752 mod数列
ユーザー ats5515ats5515
提出日時 2018-11-09 22:28:50
言語 C++11
(gcc 8.5.0)
結果
AC  
実行時間 385 ms / 2,000 ms
コード長 878 bytes
コンパイル時間 657 ms
使用メモリ 21,220 KB
最終ジャッジ日時 2022-12-26 20:23:06
合計ジャッジ時間 8,089 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
3,736 KB
testcase_01 AC 2 ms
3,688 KB
testcase_02 AC 2 ms
3,496 KB
testcase_03 AC 2 ms
3,636 KB
testcase_04 AC 1 ms
3,500 KB
testcase_05 AC 2 ms
3,728 KB
testcase_06 AC 1 ms
3,656 KB
testcase_07 AC 2 ms
3,568 KB
testcase_08 AC 2 ms
3,712 KB
testcase_09 AC 2 ms
3,724 KB
testcase_10 AC 22 ms
8,572 KB
testcase_11 AC 12 ms
5,728 KB
testcase_12 AC 18 ms
7,588 KB
testcase_13 AC 14 ms
6,652 KB
testcase_14 AC 22 ms
8,644 KB
testcase_15 AC 166 ms
4,636 KB
testcase_16 AC 242 ms
6,960 KB
testcase_17 AC 361 ms
17,528 KB
testcase_18 AC 236 ms
9,636 KB
testcase_19 AC 260 ms
11,540 KB
testcase_20 AC 342 ms
17,640 KB
testcase_21 AC 327 ms
17,244 KB
testcase_22 AC 330 ms
17,044 KB
testcase_23 AC 348 ms
17,792 KB
testcase_24 AC 332 ms
17,596 KB
testcase_25 AC 124 ms
13,156 KB
testcase_26 AC 308 ms
17,584 KB
testcase_27 AC 204 ms
14,204 KB
testcase_28 AC 282 ms
16,560 KB
testcase_29 AC 309 ms
14,456 KB
testcase_30 AC 385 ms
21,220 KB
testcase_31 AC 2 ms
3,360 KB
testcase_32 AC 2 ms
3,360 KB
testcase_33 AC 15 ms
7,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <assert.h>
using namespace std;
#define int long long
int MOD = 1000000007;
map<int, int> dp;
int P, Q;
int solve(int a) {
	if (dp.count(a) != 0) {
		return dp[a];
	}
	//cerr << a << endl;
	int m = P / a;
	int x = (P / (m + 1)) + 1;
	assert((P / a) == (P / x));
	if (x != 1)	assert((P / x) != (P / (x - 1)));
	int a1 = P%a;
	int a2 = P%x;
	return dp[a] = ((((a1 + a2) * (a - x + 1)) / 2) + solve(x - 1));
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	dp[0] = 0;
	cin >> P >> Q;
	vector<int> L(Q);
	vector<int> R(Q);
	for (int i = 0; i < Q; i++) {
		cin >> L[i] >> R[i];
	}
	for (int i = 0; i < Q; i++) {
		int res = solve(R[i]) - solve(L[i] - 1);
		cout << res << endl;
	}
}
0