結果

問題 No.1514 Squared Matching
ユーザー se1ka2se1ka2
提出日時 2021-05-21 21:53:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 883 bytes
コンパイル時間 805 ms
コンパイル使用メモリ 73,556 KB
実行使用メモリ 589,732 KB
最終ジャッジ日時 2024-04-18 15:10:51
合計ジャッジ時間 17,066 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 MLE -
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 13 ms
12,672 KB
testcase_07 AC 136 ms
115,328 KB
testcase_08 MLE -
testcase_09 AC 772 ms
497,152 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 139 ms
120,832 KB
testcase_23 AC 294 ms
237,824 KB
testcase_24 AC 550 ms
355,328 KB
testcase_25 AC 705 ms
472,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

std::vector<int> enum_prime(int n){     // containing n
    std::vector<int> res;
    if (n <= 1) return res;
    std::vector<bool> p(n + 1);
    fill(p.begin() + 2, p.end(), true);
    for(int i = 2; i <= n; i++){
        if(p[i]){
            res.push_back(i);
            for(int j = i * 2; j <= n; j += i) p[j] = false;
        }
    }
    return res;
}

int d[50000005];
ll b[50000005];

int main()
{
    int n;
    cin >> n;
    vector<int> prime = enum_prime(10000);
    for(int i = 1; i <= n; i++) d[i] = i;
    for(int p : prime){
        int q = p * p;
        for(int j = q; j <= n; j += q){
            while(d[j] % q == 0) d[j] /= q;
        }
    }
    for(int i = 1; i <= n; i++) b[d[i]]++;
    ll ans = 0;
    for(int i = 1; i <= n; i++) ans += b[i] * b[i];
    cout << ans << endl;
}
0