結果

問題 No.1514 Squared Matching
ユーザー se1ka2se1ka2
提出日時 2021-05-21 21:54:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 546 ms / 4,000 ms
コード長 884 bytes
コンパイル時間 633 ms
コンパイル使用メモリ 72,772 KB
実行使用メモリ 394,296 KB
最終ジャッジ日時 2024-04-18 15:13:05
合計ジャッジ時間 11,223 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 546 ms
394,196 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 8 ms
11,404 KB
testcase_07 AC 87 ms
79,832 KB
testcase_08 AC 515 ms
382,124 KB
testcase_09 AC 449 ms
334,032 KB
testcase_10 AC 487 ms
361,992 KB
testcase_11 AC 506 ms
375,760 KB
testcase_12 AC 523 ms
386,912 KB
testcase_13 AC 526 ms
391,460 KB
testcase_14 AC 530 ms
393,456 KB
testcase_15 AC 542 ms
393,932 KB
testcase_16 AC 542 ms
393,900 KB
testcase_17 AC 544 ms
394,264 KB
testcase_18 AC 539 ms
394,292 KB
testcase_19 AC 535 ms
394,296 KB
testcase_20 AC 536 ms
394,296 KB
testcase_21 AC 537 ms
394,168 KB
testcase_22 AC 91 ms
84,752 KB
testcase_23 AC 200 ms
162,060 KB
testcase_24 AC 315 ms
239,584 KB
testcase_25 AC 434 ms
317,612 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];
int 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