結果

問題 No.752 mod数列
ユーザー ats5515ats5515
提出日時 2018-11-09 22:28:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 403 ms / 2,000 ms
コード長 878 bytes
コンパイル時間 866 ms
コンパイル使用メモリ 93,256 KB
実行使用メモリ 21,888 KB
最終ジャッジ日時 2024-05-01 05:05:35
合計ジャッジ時間 7,923 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 20 ms
9,088 KB
testcase_11 AC 11 ms
6,940 KB
testcase_12 AC 16 ms
8,064 KB
testcase_13 AC 14 ms
7,040 KB
testcase_14 AC 21 ms
9,216 KB
testcase_15 AC 168 ms
6,944 KB
testcase_16 AC 236 ms
7,552 KB
testcase_17 AC 351 ms
18,688 KB
testcase_18 AC 247 ms
9,728 KB
testcase_19 AC 264 ms
11,520 KB
testcase_20 AC 345 ms
17,664 KB
testcase_21 AC 342 ms
17,536 KB
testcase_22 AC 337 ms
17,152 KB
testcase_23 AC 367 ms
17,920 KB
testcase_24 AC 357 ms
17,536 KB
testcase_25 AC 119 ms
14,080 KB
testcase_26 AC 311 ms
18,432 KB
testcase_27 AC 209 ms
14,976 KB
testcase_28 AC 275 ms
17,664 KB
testcase_29 AC 302 ms
14,976 KB
testcase_30 AC 403 ms
21,888 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 14 ms
7,808 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