結果

問題 No.1233 割り切れない気持ち
ユーザー hiro71687khiro71687k
提出日時 2023-03-01 02:26:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 389 ms / 3,153 ms
コード長 3,127 bytes
コンパイル時間 4,468 ms
コンパイル使用メモリ 266,572 KB
実行使用メモリ 32,156 KB
最終ジャッジ日時 2023-10-14 08:17:51
合計ジャッジ時間 17,350 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
30,356 KB
testcase_01 AC 39 ms
30,288 KB
testcase_02 AC 37 ms
30,384 KB
testcase_03 AC 40 ms
30,732 KB
testcase_04 AC 40 ms
30,188 KB
testcase_05 AC 39 ms
30,368 KB
testcase_06 AC 39 ms
30,368 KB
testcase_07 AC 111 ms
30,748 KB
testcase_08 AC 173 ms
30,984 KB
testcase_09 AC 314 ms
31,872 KB
testcase_10 AC 330 ms
31,812 KB
testcase_11 AC 101 ms
30,652 KB
testcase_12 AC 379 ms
31,768 KB
testcase_13 AC 381 ms
31,880 KB
testcase_14 AC 389 ms
31,940 KB
testcase_15 AC 388 ms
32,004 KB
testcase_16 AC 389 ms
32,020 KB
testcase_17 AC 90 ms
31,844 KB
testcase_18 AC 367 ms
31,816 KB
testcase_19 AC 112 ms
31,784 KB
testcase_20 AC 97 ms
32,156 KB
testcase_21 AC 101 ms
32,052 KB
testcase_22 AC 101 ms
32,008 KB
testcase_23 AC 101 ms
31,844 KB
testcase_24 AC 100 ms
32,052 KB
testcase_25 AC 101 ms
31,816 KB
testcase_26 AC 101 ms
31,876 KB
testcase_27 AC 297 ms
31,932 KB
testcase_28 AC 296 ms
32,028 KB
testcase_29 AC 304 ms
31,852 KB
testcase_30 AC 297 ms
32,012 KB
testcase_31 AC 290 ms
31,844 KB
testcase_32 AC 289 ms
31,968 KB
testcase_33 AC 282 ms
31,764 KB
testcase_34 AC 283 ms
31,836 KB
testcase_35 AC 283 ms
31,944 KB
testcase_36 AC 277 ms
31,772 KB
testcase_37 AC 38 ms
30,456 KB
testcase_38 AC 351 ms
31,788 KB
testcase_39 AC 361 ms
31,840 KB
testcase_40 AC 359 ms
31,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ld=double;
ld pie=3.14159265359;
ll mod=998244353;
long long inf=100000000000000001;
struct Eratosthenes {
    // テーブル
    vector<bool> isprime;

    // 整数 i を割り切る最小の素数
    vector<ll> minfactor;

    vector<ll>mobius;

    // コンストラクタで篩を回す
    Eratosthenes(ll N) : isprime(N+1, true),
                          minfactor(N+1, -1),
                          mobius(N+1,1) {
        // 1 は予めふるい落としておく
        isprime[1] = false;
        minfactor[1] = 1;

        // 篩
        for (ll p = 2; p <= N; ++p) {
            // すでに合成数であるものはスキップする
            if (!isprime[p]) continue;

            // p についての情報更新
            minfactor[p] = p;
            mobius[p]=-1;

            // p 以外の p の倍数から素数ラベルを剥奪
            for (ll q = p * 2; q <= N; q += p) {
                // q は合成数なのでふるい落とす
                isprime[q] = false;

                // q は p で割り切れる旨を更新
                if (minfactor[q] == -1) minfactor[q] = p;
                if ((q / p) % p == 0) mobius[q] = 0;
                else mobius[q] = -mobius[q];
            }
        }
    }

    // 高速素因数分解
    // pair (素因子, 指数) の vector を返す
    vector<pair<ll,ll>> factorize(ll n) {
        vector<pair<ll,ll>> res;
        while (n > 1) {
            ll p = minfactor[n];
            ll exp = 0;

            // n で割り切れる限り割る
            while (minfactor[n] == p) {
                n /= p;
                ++exp;
            }
            res.emplace_back(p, exp);
        }
        return res;
    }
    vector<ll>divisors(ll n){
        vector<ll>res({1});
        auto pf=factorize(n);
        for (auto p : pf)
        {
            ll s=(ll)res.size();
            for (ll i = 0; i < s; i++)
            {
                ll v=1;
                for (ll j = 0; j < p.second; j++)
                {
                    v*=p.first;
                    res.push_back(res[i]*v);
                }
                
            }
            
        }
        return res;
    }  
};
ll op(ll a,ll b){
    return a+b;
}
ll e(){
    return 0;
}
int main(){
    ll n;
    cin >> n;
    vector<ll>a(n);
    vector<ll>memo(300000,0);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
        memo[a[i]]+=1;
    }
    sort(a.begin(),a.end());
    Eratosthenes er(300000);
    vector<ll>b(500001,0);
    segtree<ll,op,e>seg1(b),seg2(b);//seg1:個数 seg2:数
    ll saigo=200001;
    ll ans=0;
    for (ll i = 0; i < n; i++)
    {
        seg1.set(a[i],seg1.get(a[i])+1);
        seg2.set(a[i],seg2.get(a[i])+a[i]);
    }
    for (ll i = a[0]; i <=a[n-1]; i++)
    {
        for (ll j = 0; j*i <=a[n-1] ; j++)
        {
            ll ko=seg1.prod(i*j+1,i*(j+1));
            ll x=seg2.prod(i*j+1,i*(j+1));
            ans+=(x-ko*j*i)*memo[i];
        }
    }
    cout << ans << endl;
}
0