結果

問題 No.1514 Squared Matching
ユーザー rin204rin204
提出日時 2022-01-28 19:16:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 725 ms / 4,000 ms
コード長 586 bytes
コンパイル時間 1,914 ms
コンパイル使用メモリ 199,664 KB
実行使用メモリ 394,112 KB
最終ジャッジ日時 2024-06-09 12:19:40
合計ジャッジ時間 13,988 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
5,248 KB
testcase_01 AC 725 ms
394,112 KB
testcase_02 AC 28 ms
5,376 KB
testcase_03 AC 26 ms
5,376 KB
testcase_04 AC 27 ms
5,376 KB
testcase_05 AC 27 ms
5,376 KB
testcase_06 AC 32 ms
9,600 KB
testcase_07 AC 149 ms
77,952 KB
testcase_08 AC 668 ms
380,032 KB
testcase_09 AC 543 ms
332,544 KB
testcase_10 AC 590 ms
359,936 KB
testcase_11 AC 614 ms
374,912 KB
testcase_12 AC 633 ms
385,280 KB
testcase_13 AC 641 ms
390,272 KB
testcase_14 AC 641 ms
392,448 KB
testcase_15 AC 646 ms
393,472 KB
testcase_16 AC 653 ms
393,856 KB
testcase_17 AC 648 ms
394,112 KB
testcase_18 AC 648 ms
394,056 KB
testcase_19 AC 655 ms
394,112 KB
testcase_20 AC 649 ms
394,056 KB
testcase_21 AC 643 ms
394,052 KB
testcase_22 AC 112 ms
81,536 KB
testcase_23 AC 246 ms
159,744 KB
testcase_24 AC 381 ms
237,824 KB
testcase_25 AC 523 ms
315,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int div_[50001000];
int cnt[50001000];
int main(void){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) div_[i] = 1;
    for(int j = 2; j * j <= n; j++){
        for(int k = j * j; k <= n; k += j * j){
            div_[k] = j * j;
        }
    }

    long long ans = 0;
    for(int i = 1; i <= n; i++){
        int j = i;
        if (div_[i] != 1){
            j /= div_[i];
        }
        div_[i] = j;
        cnt[j]++;
    }
    for(auto c: cnt){
        ans += (long long) c * (long long) c;
    }
    cout << ans << "\n";
}
0