結果

問題 No.752 mod数列
ユーザー parukiparuki
提出日時 2018-11-24 09:00:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,634 bytes
コンパイル時間 1,430 ms
コンパイル使用メモリ 164,924 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 04:48:28
合計ジャッジ時間 7,034 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 145 ms
4,376 KB
testcase_16 AC 147 ms
4,376 KB
testcase_17 TLE -
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 #

#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>;

// 余りはO(sqrt(N)個の等差数列)
const int T = 40000;
int P, Q, med = -1;
ll sm[T], upto[T];

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

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

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