結果

問題 No.752 mod数列
ユーザー 👑 jupirojupiro
提出日時 2020-05-19 11:34:47
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 359 ms / 2,000 ms
コード長 1,674 bytes
コンパイル時間 1,158 ms
コンパイル使用メモリ 126,568 KB
実行使用メモリ 82,028 KB
最終ジャッジ日時 2024-04-09 22:05:15
合計ジャッジ時間 8,989 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
81,776 KB
testcase_01 AC 120 ms
81,656 KB
testcase_02 AC 118 ms
81,928 KB
testcase_03 AC 119 ms
81,800 KB
testcase_04 AC 122 ms
81,900 KB
testcase_05 AC 122 ms
81,864 KB
testcase_06 AC 121 ms
81,824 KB
testcase_07 AC 124 ms
81,788 KB
testcase_08 AC 124 ms
81,832 KB
testcase_09 AC 120 ms
81,820 KB
testcase_10 AC 121 ms
81,856 KB
testcase_11 AC 124 ms
81,732 KB
testcase_12 AC 127 ms
81,792 KB
testcase_13 AC 124 ms
81,840 KB
testcase_14 AC 122 ms
81,800 KB
testcase_15 AC 146 ms
81,848 KB
testcase_16 AC 148 ms
81,848 KB
testcase_17 AC 359 ms
81,820 KB
testcase_18 AC 156 ms
81,780 KB
testcase_19 AC 153 ms
81,912 KB
testcase_20 AC 164 ms
81,872 KB
testcase_21 AC 161 ms
81,888 KB
testcase_22 AC 165 ms
81,868 KB
testcase_23 AC 163 ms
81,808 KB
testcase_24 AC 168 ms
82,016 KB
testcase_25 AC 213 ms
81,888 KB
testcase_26 AC 301 ms
81,908 KB
testcase_27 AC 216 ms
82,028 KB
testcase_28 AC 275 ms
81,904 KB
testcase_29 AC 212 ms
81,856 KB
testcase_30 AC 307 ms
81,964 KB
testcase_31 AC 123 ms
81,852 KB
testcase_32 AC 120 ms
81,892 KB
testcase_33 AC 119 ms
81,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
long double PI = acos(-1);

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


ll sum[10000001];
ll P, Q;

ll solve(ll x) {
	ll res = P * x;
	if (x <= 10000000) res -= sum[x];
	else {
		res -= sum[10000000];
		ll i = 1;
		for (;; i++) {
			ll lf = max(P / (i + 1) + 1, 10000001LL);
			ll rg = min(P / i, x);
			//cout << x << " " << lf << " " << rg << endl;
			if (rg <= 10000000) break;
			if (lf > rg) continue;

			res -= i * (lf + rg) * (rg - lf + 1) / 2;
		}
	}
	return res;
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	scanf("%lld %lld", &P, &Q);
	for (ll i = 1; i <= 10000000; i++) {
		sum[i] = sum[i - 1];
		sum[i] += P / i * i;
	}
	while (Q--) {
		ll l, r; scanf("%lld %lld", &l, &r);
		l--;
		ll res = solve(r);
		if (l) res -= solve(l);
		printf("%lld\n", res);
	}
	return 0;

}
0