結果
問題 |
No.1514 Squared Matching
|
ユーザー |
![]() |
提出日時 | 2025-07-07 01:51:55 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 762 ms / 4,000 ms |
コード長 | 960 bytes |
コンパイル時間 | 1,253 ms |
コンパイル使用メモリ | 105,600 KB |
実行使用メモリ | 198,528 KB |
最終ジャッジ日時 | 2025-07-07 01:52:13 |
合計ジャッジ時間 | 15,215 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <iostream> #include <math.h> #include <numeric> #include <vector> const int MAXN = 50'000'000; void solve() { int n; std::cin >> n; int m = std::sqrt(n) + 1; std::vector<int> squarefree(n + 1); std::vector<bool> isPrime(m + 1, true); std::iota(squarefree.begin(), squarefree.end(), 0); isPrime[0] = isPrime[1] = false; for (int i = 2; i <= m; i++) { if (!isPrime[i]) { continue; } int k = i * i; for (int j = k; j <= m; j += i) { isPrime[j] = false; } for (int j = k; j <= n; j += k) { while (squarefree[j] % k == 0) { squarefree[j] /= k; } } } int res = 0; for (int i = 1; i <= n; i++) { res += sqrt(n / squarefree[i]); } std::cout << res << std::endl; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); solve(); return 0; }