結果

問題 No.752 mod数列
ユーザー ats5515
提出日時 2018-11-09 22:28:50
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 415 ms / 2,000 ms
コード長 878 bytes
コンパイル時間 887 ms
コンパイル使用メモリ 92,508 KB
実行使用メモリ 21,888 KB
最終ジャッジ日時 2024-11-21 06:20:25
合計ジャッジ時間 7,496 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

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