結果

問題 No.752 mod数列
ユーザー ats5515ats5515
提出日時 2018-11-09 22:28:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 456 ms / 2,000 ms
コード長 878 bytes
コンパイル時間 1,586 ms
コンパイル使用メモリ 86,944 KB
実行使用メモリ 21,312 KB
最終ジャッジ日時 2023-08-13 11:47:45
合計ジャッジ時間 8,838 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 21 ms
8,420 KB
testcase_11 AC 12 ms
5,660 KB
testcase_12 AC 18 ms
7,552 KB
testcase_13 AC 15 ms
6,616 KB
testcase_14 AC 22 ms
8,556 KB
testcase_15 AC 171 ms
4,796 KB
testcase_16 AC 265 ms
6,996 KB
testcase_17 AC 414 ms
17,548 KB
testcase_18 AC 272 ms
9,896 KB
testcase_19 AC 294 ms
11,548 KB
testcase_20 AC 407 ms
17,556 KB
testcase_21 AC 380 ms
17,280 KB
testcase_22 AC 399 ms
17,040 KB
testcase_23 AC 407 ms
17,820 KB
testcase_24 AC 405 ms
17,576 KB
testcase_25 AC 134 ms
13,072 KB
testcase_26 AC 356 ms
17,544 KB
testcase_27 AC 238 ms
14,208 KB
testcase_28 AC 320 ms
16,488 KB
testcase_29 AC 330 ms
14,452 KB
testcase_30 AC 456 ms
21,312 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 14 ms
7,212 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