結果

問題 No.752 mod数列
ユーザー parukiparuki
提出日時 2018-11-24 09:05:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,199 ms / 2,000 ms
コード長 1,609 bytes
コンパイル時間 1,286 ms
コンパイル使用メモリ 165,808 KB
実行使用メモリ 19,204 KB
最終ジャッジ日時 2023-08-26 04:48:49
合計ジャッジ時間 8,871 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
19,156 KB
testcase_01 AC 11 ms
19,008 KB
testcase_02 AC 11 ms
18,956 KB
testcase_03 AC 10 ms
19,004 KB
testcase_04 AC 11 ms
19,080 KB
testcase_05 AC 11 ms
18,944 KB
testcase_06 AC 10 ms
19,008 KB
testcase_07 AC 11 ms
19,044 KB
testcase_08 AC 11 ms
18,940 KB
testcase_09 AC 11 ms
19,204 KB
testcase_10 AC 11 ms
18,948 KB
testcase_11 AC 11 ms
19,060 KB
testcase_12 AC 13 ms
18,948 KB
testcase_13 AC 13 ms
19,104 KB
testcase_14 AC 12 ms
18,956 KB
testcase_15 AC 138 ms
19,032 KB
testcase_16 AC 151 ms
19,020 KB
testcase_17 AC 1,199 ms
18,964 KB
testcase_18 AC 157 ms
18,944 KB
testcase_19 AC 159 ms
19,064 KB
testcase_20 AC 154 ms
18,976 KB
testcase_21 AC 155 ms
19,176 KB
testcase_22 AC 154 ms
18,968 KB
testcase_23 AC 158 ms
19,008 KB
testcase_24 AC 160 ms
18,964 KB
testcase_25 AC 56 ms
19,088 KB
testcase_26 AC 571 ms
18,960 KB
testcase_27 AC 317 ms
18,956 KB
testcase_28 AC 493 ms
18,964 KB
testcase_29 AC 438 ms
19,104 KB
testcase_30 AC 160 ms
19,032 KB
testcase_31 AC 11 ms
18,980 KB
testcase_32 AC 11 ms
19,012 KB
testcase_33 AC 11 ms
19,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

// 10^3 * 10^5
// 余りはO(sqrt(N)個の等差数列)
const int T = 1000001;
int P, Q;
ll sm[T], upto[T];

void solve() {
    cin >> P >> Q;

    for (int i = 1; i<T; ++i) {
        sm[i] = sm[i - 1] + P % i;
        upto[i] = P / i;
    }
    upto[0] = 1000000000;

    while (Q--) {
        int l, r;
        cin >> l >> r;
        ll ans = 0;
        if (r < T) {
            ans = sm[r] - sm[l - 1];
        } else {
            if (l < T) {
                ans += sm[T-1] - sm[l - 1];
            }
            // n = med+1からまとめて足す
            ll to = P / r, L = max(l, T);
            ll diff = P / L;

            while (diff >= to) {
                ll R = min<ll>(upto[diff], r);
                ll a = P % L, n = R - L + 1;
                ans += (2 * a + (n-1)*(-diff))*n / 2;
                diff--;
                L = R + 1;
            }
        }
        cout << ans << endl;
    }
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
0