結果

問題 No.1514 Squared Matching
ユーザー MisterMister
提出日時 2021-05-21 22:28:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 675 bytes
コンパイル時間 792 ms
コンパイル使用メモリ 78,180 KB
実行使用メモリ 589,352 KB
最終ジャッジ日時 2024-04-18 16:02:10
合計ジャッジ時間 14,161 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 MLE -
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 12 ms
12,256 KB
testcase_07 AC 124 ms
115,200 KB
testcase_08 MLE -
testcase_09 AC 611 ms
496,896 KB
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 AC 133 ms
120,448 KB
testcase_23 AC 260 ms
237,512 KB
testcase_24 AC 393 ms
354,732 KB
testcase_25 AC 579 ms
471,868 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<lint> cnt(n + 1, 0);
    for (int x = 1; x <= n; ++x) ++cnt[xs[x]];

    lint ans = 0;
    for (auto c : cnt) ans += c * c;
    cout << ans << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
0