結果

問題 No.752 mod数列
ユーザー tsutajtsutaj
提出日時 2019-03-29 22:03:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,030 bytes
コンパイル時間 1,032 ms
コンパイル使用メモリ 100,408 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-24 16:45:39
合計ジャッジ時間 6,453 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int P, Q; cin >> P >> Q;
    while(Q--) {
        int l, r; cin >> l >> r;
        int vl = P / l, vr = P / r, cur = l;
        int ans = 0;
        for(int div=vl; div>=vr; div--) {
            if(div == 0) {
                int ll = P + 1;
                int rr = r;
                int add = 2 * P * (rr - ll + 1) / 2;
                ans += add;
            }
            else {
                // fprintf(stderr, "div = %lld\n", div);
                int ll = max(P / (div + 1) + 1, l);
                int rr = min(P / div, r);
                
                int lll = P % ll, rrr = P % rr;
                // fprintf(stderr, "ll = %lld, rr = %lld, lll = %lld, rrr = %lld\n", ll, rr, lll, rrr);
                int add = (lll + rrr) * (rr - ll + 1) / 2;
                ans += add;
                // fprintf(stderr, "value = %lld\n", add);
                if(P / cur != P / (cur + 1)) {
                    cur++;
                    div = P / cur + 1;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}
0