結果
問題 |
No.1514 Squared Matching
|
ユーザー |
![]() |
提出日時 | 2025-07-07 12:43:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,158 ms / 4,000 ms |
コード長 | 1,051 bytes |
コンパイル時間 | 1,990 ms |
コンパイル使用メモリ | 193,716 KB |
実行使用メモリ | 394,152 KB |
最終ジャッジ日時 | 2025-07-07 12:44:14 |
合計ジャッジ時間 | 39,512 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int N = 5e7 + 5; int n, ct[N], res = 0, st[N]; void snt() { for (int i = 2; i <= n; i++) st[i] = i; for (int i = 2; i * i <= n; i++) { if (st[i] == i) { for (int j = i * i; j * j <= n; j += i) { if (st[j] == j) st[j] = i; } for (int j = i * i; j <= n; j += i * i) { if (st[j] == j) st[j] = i; } } } } int get(int a) { int ans = 1; while (a > 1) { int p = st[a]; int cnt = 0; while (a % p == 0) { a /= p; cnt ^= 1; } if (cnt) ans *= p; } if (a > 1) { ans *= a; } return ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; snt(); for (int i = 1; i <= n; i++) { ct[get(i)]++; } for (int i = 1; i <= n; i++) { res += ct[i] * (ct[i] - 1) + 1; } cout << res; }