結果
問題 |
No.719 Coprime
|
ユーザー |
![]() |
提出日時 | 2018-08-18 20:14:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,629 bytes |
コンパイル時間 | 910 ms |
コンパイル使用メモリ | 80,312 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-06 19:44:50 |
合計ジャッジ時間 | 2,855 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 WA * 37 |
ソースコード
#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; }