結果
問題 | No.1514 Squared Matching |
ユーザー |
|
提出日時 | 2021-05-21 22:29:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 589 ms / 4,000 ms |
コード長 | 680 bytes |
コンパイル時間 | 681 ms |
コンパイル使用メモリ | 73,192 KB |
最終ジャッジ日時 | 2025-01-21 15:41:03 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <iostream> #include <numeric> #include <vector> using namespace std; using lint = long long; void solve() { lint n; cin >> n; vector<int> xs(n + 1); iota(xs.begin(), xs.end(), 0); for (int k = 2; k * k <= n; ++k) { auto s = k * k; if (xs[s] != s) continue; for (int x = s; x <= n; x += s) { while (xs[x] % s == 0) xs[x] /= s; } } vector<int> cnt(n + 1, 0); for (int x = 1; x <= n; ++x) ++cnt[xs[x]]; lint ans = 0; for (auto c : cnt) ans += lint(c) * c; cout << ans << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }