結果
| 問題 |
No.1514 Squared Matching
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-07-07 12:00:37 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 923 bytes |
| コンパイル時間 | 2,103 ms |
| コンパイル使用メモリ | 192,092 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-07-07 12:00:46 |
| 合計ジャッジ時間 | 8,057 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 TLE * 1 -- * 24 |
ソースコード
#include <bits/stdc++.h>
#define int long long
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 <= n; j += i) {
if (st[j] == j)
st[j] = i;
}
}
}
}
int get(int a) {
int ans = 1, x = a;
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() {
cin >> n;
snt();
for (int i = 1; i <= n; i++) {
ct[get(i)]++;
//cout << i << ' '<< get(i) << '\n';
}
for (int i = 1; i <= n; i++) {
res += ct[i] * (ct[i] - 1);
}
cout << res + n;
}
vjudge1