結果

問題 No.719 Coprime
ユーザー commycommy
提出日時 2018-08-18 20:14:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,629 bytes
コンパイル時間 943 ms
コンパイル使用メモリ 80,532 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-24 11:56:38
合計ジャッジ時間 2,786 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    int N;
    cin >> N;
    vector<bool> isPrime(N + 1, true);
    vector<int> Prime;
    isPrime[0] = isPrime[1] = false;
    REP(i, 2, N + 1) {
        if (isPrime[i]) {
            Prime.push_back(i);
            for (int j = 2 * i; j < N + 1; j += i) {
                isPrime[j] = false;
            }
        }
    }

    const int PSZ = Prime.size();
    vector<int> memo(PSZ, 0);
    REP(i, 2, N + 1) {
        vector<int> plst;
        REP(j, 0, PSZ) {
            if (i % Prime[j] == 0 && memo[j] != 0) {
                plst.push_back(memo[j]);
            }
        }
        sort(begin(plst), end(plst));
        plst.erase(unique(begin(plst), end(plst)), end(plst));
        int cnt = 0;
        for (int &n : plst) {
            cnt += n;
        }
        if (i > cnt) {
            REP(j, 0, PSZ) {
                if (i % Prime[j] == 0) {
                    memo[j] = i;
                }
            }
        }
    }
    sort(begin(memo), end(memo));
    memo.erase(unique(begin(memo), end(memo)), end(memo));
    int ans = 0;
    for (int &n : memo) {
        ans += n;
    }
    cout << ans << endl;
    return 0;
}
0