結果

問題 No.1276 3枚のカード
ユーザー 👑 NachiaNachia
提出日時 2020-10-30 23:19:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 650 ms / 2,000 ms
コード長 2,732 bytes
コンパイル時間 1,680 ms
コンパイル使用メモリ 169,652 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-29 08:25:24
合計ジャッジ時間 22,039 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 547 ms
4,380 KB
testcase_11 AC 257 ms
4,376 KB
testcase_12 AC 327 ms
4,376 KB
testcase_13 AC 342 ms
4,376 KB
testcase_14 AC 30 ms
4,380 KB
testcase_15 AC 276 ms
4,376 KB
testcase_16 AC 597 ms
4,376 KB
testcase_17 AC 319 ms
4,380 KB
testcase_18 AC 242 ms
4,376 KB
testcase_19 AC 394 ms
4,380 KB
testcase_20 AC 230 ms
4,376 KB
testcase_21 AC 239 ms
4,376 KB
testcase_22 AC 610 ms
4,380 KB
testcase_23 AC 27 ms
4,380 KB
testcase_24 AC 373 ms
4,376 KB
testcase_25 AC 123 ms
4,376 KB
testcase_26 AC 464 ms
4,380 KB
testcase_27 AC 532 ms
4,380 KB
testcase_28 AC 512 ms
4,380 KB
testcase_29 AC 291 ms
4,380 KB
testcase_30 AC 55 ms
4,380 KB
testcase_31 AC 24 ms
4,380 KB
testcase_32 AC 132 ms
4,376 KB
testcase_33 AC 8 ms
4,380 KB
testcase_34 AC 91 ms
4,376 KB
testcase_35 AC 84 ms
4,376 KB
testcase_36 AC 6 ms
4,376 KB
testcase_37 AC 80 ms
4,380 KB
testcase_38 AC 53 ms
4,380 KB
testcase_39 AC 139 ms
4,376 KB
testcase_40 AC 581 ms
4,380 KB
testcase_41 AC 479 ms
4,376 KB
testcase_42 AC 519 ms
4,380 KB
testcase_43 AC 452 ms
4,380 KB
testcase_44 AC 645 ms
4,380 KB
testcase_45 AC 582 ms
4,376 KB
testcase_46 AC 583 ms
4,380 KB
testcase_47 AC 480 ms
4,380 KB
testcase_48 AC 460 ms
4,376 KB
testcase_49 AC 522 ms
4,376 KB
testcase_50 AC 577 ms
4,380 KB
testcase_51 AC 495 ms
4,380 KB
testcase_52 AC 423 ms
4,376 KB
testcase_53 AC 499 ms
4,380 KB
testcase_54 AC 576 ms
4,376 KB
testcase_55 AC 443 ms
4,376 KB
testcase_56 AC 427 ms
4,380 KB
testcase_57 AC 551 ms
4,380 KB
testcase_58 AC 572 ms
4,376 KB
testcase_59 AC 501 ms
4,376 KB
testcase_60 AC 650 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

template<ULL M>
struct static_modint {
    ULL x;
    static_modint(ULL val = 0) : x(val) {}

    static_modint& operator+=(static_modint r) { x += r.x; if (x >= M) x -= M; return *this; }
    static_modint operator+(static_modint r) const { static_modint res = x; return res += r; }
    static_modint& operator-=(static_modint r) { x += M - r.x; if (x >= M) x -= M; return *this; }
    static_modint operator-(static_modint r) const { static_modint res = x; return res -= r; }
    static_modint& operator*=(static_modint r) { x = x * r.x % M; return *this; }
    static_modint operator*(static_modint r) const { return static_modint(x * r.x % M); }
    static_modint pow(ULL r) const {
        if (r == 0) return static_modint(1);
        static_modint res = pow(r / 2);
        res *= res;
        if (r % 2) res *= *this;
        return res;
    }
    static_modint& operator/=(static_modint r) { *this *= r.pow(M - 2); return *this; }
    static_modint operator/(static_modint r) const { return *this * (r.pow(M - 2)); }
    ULL& operator*() { return x; }
    const ULL& operator*() const { return x; }
    bool operator==(static_modint r) const { return x == r; }
    bool operator!=(static_modint r) const { return x != r; }
};

static const ULL M = 1000000007;
using MLL = static_modint<M>;

vector<ULL> NMul; // number of greater multiples
vector<ULL> RNMul; // number of integers that has just the number of greater multiples

ULL F(ULL n) {
    ULL ans = 0;
    for (ULL i = 1; i * i <= n; i++) {
        ULL f = n / i;
        if (f * f > n) ans += f - 1;
    }
    for (ULL i = 1; i * i <= n; i++) ans += (i - 1) * (n / i - n / (i + 1));
    ans -= n - 1;
    return ans;
}

int main() {
    ULL N; cin >> N;

    NMul = { 0 };
    RNMul = {};

    for (ULL i = 1; i * i <= N; i++) {
        NMul.push_back(N / i - 1);
        if (NMul.back() * NMul.back() <= N) NMul.pop_back();
    }
    for (ULL i = 0; i * i <= N; i++) {
        RNMul.push_back(N / (i + 1) - N / (i + 2));
    }

    MLL ans = MLL(N % M) * MLL((N - 1) % M) * MLL((N - 2) % M);

    for (ULL i = 1; i < NMul.size(); i++) {
        MLL tmp = 0;
        tmp += (NMul[i] * (NMul[i] - 1) % M);
        tmp += ((N - 2) * (N - 1 - NMul[i]) % M);
        MLL Fx = F(NMul[i] + 1) % M;
        tmp += Fx;
        ans -= tmp;
    }
    for (ULL i = 0; i < RNMul.size(); i++) {
        MLL tmp = 0;
        tmp += (i * (i - 1) % M);
        tmp += ((N - 2) * (N - 1 - i) % M);
        MLL Fx = F(i + 1) % M;
        tmp += Fx;
        tmp *= RNMul[i];
        ans -= tmp;
    }

    cout << *ans << endl;

	return 0;
}
0