結果

問題 No.1514 Squared Matching
ユーザー zhanghonghe2zhanghonghe2
提出日時 2021-06-26 16:33:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 676 ms / 4,000 ms
コード長 1,001 bytes
コンパイル時間 499 ms
コンパイル使用メモリ 67,884 KB
実行使用メモリ 394,500 KB
最終ジャッジ日時 2023-09-07 15:19:12
合計ジャッジ時間 12,736 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,636 KB
testcase_01 AC 662 ms
394,336 KB
testcase_02 AC 2 ms
5,848 KB
testcase_03 AC 3 ms
5,648 KB
testcase_04 AC 3 ms
5,648 KB
testcase_05 AC 2 ms
5,800 KB
testcase_06 AC 12 ms
12,872 KB
testcase_07 AC 129 ms
79,864 KB
testcase_08 AC 640 ms
382,300 KB
testcase_09 AC 553 ms
334,120 KB
testcase_10 AC 610 ms
362,100 KB
testcase_11 AC 629 ms
377,792 KB
testcase_12 AC 646 ms
386,996 KB
testcase_13 AC 656 ms
391,664 KB
testcase_14 AC 666 ms
393,428 KB
testcase_15 AC 662 ms
394,064 KB
testcase_16 AC 665 ms
394,204 KB
testcase_17 AC 672 ms
394,292 KB
testcase_18 AC 676 ms
394,496 KB
testcase_19 AC 667 ms
394,236 KB
testcase_20 AC 670 ms
394,500 KB
testcase_21 AC 664 ms
394,232 KB
testcase_22 AC 133 ms
83,664 KB
testcase_23 AC 265 ms
161,600 KB
testcase_24 AC 416 ms
239,624 KB
testcase_25 AC 539 ms
317,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;

const int maxn=5e7+10;
const int maxn2=5e4+10;
int Hash[maxn];
int sum[maxn];
int prime[maxn2];
int vis[maxn2];
int cnt=0;

void init(){
    for(int i=2;i<maxn2;i++){
        if(!vis[i]) {
            for (int j = i; j < maxn2; j += i) {
                vis[j]=true;
            }
            prime[++cnt]=i;
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    int N;cin>>N;
    init();

    for(int i=1;i<=N;i++){
        Hash[i]=i;
    }


    for(int idx=1;prime[idx]*prime[idx]<=N;idx++){
        for(int i=1;i*prime[idx]*prime[idx]<=N;i++){
            int now=i*prime[idx]*prime[idx];
            int k=prime[idx]*prime[idx];
            while(Hash[now]%k==0){
                Hash[now]/=k;
            }
        }
    }

    int ans=0;
    for(int i=1;i<=N;i++){
        ans+=sum[Hash[i]]*2;
        ans+=1;
        sum[Hash[i]]+=1;
    }
    cout<<ans<<endl;
    return 0;
}
0