結果

問題 No.1514 Squared Matching
ユーザー MisterMister
提出日時 2021-05-21 22:29:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 658 ms / 4,000 ms
コード長 680 bytes
コンパイル時間 856 ms
コンパイル使用メモリ 77,440 KB
実行使用メモリ 393,908 KB
最終ジャッジ日時 2024-04-18 16:03:45
合計ジャッジ時間 11,426 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 658 ms
393,852 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 9 ms
9,224 KB
testcase_07 AC 96 ms
77,748 KB
testcase_08 AC 567 ms
379,592 KB
testcase_09 AC 465 ms
332,408 KB
testcase_10 AC 514 ms
359,612 KB
testcase_11 AC 549 ms
374,728 KB
testcase_12 AC 574 ms
384,896 KB
testcase_13 AC 584 ms
390,056 KB
testcase_14 AC 572 ms
392,240 KB
testcase_15 AC 587 ms
393,160 KB
testcase_16 AC 579 ms
393,540 KB
testcase_17 AC 579 ms
393,616 KB
testcase_18 AC 582 ms
393,908 KB
testcase_19 AC 582 ms
393,884 KB
testcase_20 AC 589 ms
393,776 KB
testcase_21 AC 581 ms
393,864 KB
testcase_22 AC 99 ms
81,336 KB
testcase_23 AC 214 ms
159,324 KB
testcase_24 AC 341 ms
237,640 KB
testcase_25 AC 460 ms
315,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0