結果

問題 No.752 mod数列
ユーザー 👑 jupirojupiro
提出日時 2020-05-19 11:26:59
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,619 bytes
コンパイル時間 1,218 ms
コンパイル使用メモリ 126,256 KB
実行使用メモリ 88,804 KB
最終ジャッジ日時 2024-04-09 22:04:49
合計ジャッジ時間 7,401 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
88,804 KB
testcase_01 AC 125 ms
81,852 KB
testcase_02 AC 126 ms
81,668 KB
testcase_03 AC 125 ms
81,872 KB
testcase_04 AC 125 ms
81,936 KB
testcase_05 AC 125 ms
81,792 KB
testcase_06 AC 126 ms
81,792 KB
testcase_07 AC 125 ms
81,816 KB
testcase_08 AC 126 ms
81,808 KB
testcase_09 AC 125 ms
81,876 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

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];
		for (ll i = 1;; i++) {
			ll lf = min(P / (i + 1) + 1, 10000001LL);
			ll rg = max(P / i, x);
			if (lf > rg) continue;
			if (rg <= 10000000) break;
			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