結果

問題 No.1514 Squared Matching
ユーザー vjudge1
提出日時 2025-07-07 12:19:48
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 968 bytes
コンパイル時間 1,915 ms
コンパイル使用メモリ 193,836 KB
実行使用メモリ 378,788 KB
最終ジャッジ日時 2025-07-07 12:19:56
合計ジャッジ時間 7,499 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1 TLE * 1 -- * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 <= 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() {
    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)]++;
        //cout << i << ' '<< get(i) << '\n';
    }
    for (int i = 1; i <= n; i++) {
        res += ct[i] * (ct[i] - 1) + 1;
    }
    cout << res;
}
0