結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,636 KB
testcase_01 AC 708 ms
394,252 KB
testcase_02 AC 2 ms
5,812 KB
testcase_03 AC 3 ms
5,680 KB
testcase_04 AC 3 ms
5,708 KB
testcase_05 AC 2 ms
5,724 KB
testcase_06 AC 12 ms
12,764 KB
testcase_07 AC 126 ms
79,792 KB
testcase_08 AC 644 ms
381,112 KB
testcase_09 AC 563 ms
334,096 KB
testcase_10 AC 611 ms
362,064 KB
testcase_11 AC 631 ms
377,732 KB
testcase_12 AC 647 ms
386,568 KB
testcase_13 AC 660 ms
391,660 KB
testcase_14 AC 665 ms
393,416 KB
testcase_15 AC 671 ms
393,848 KB
testcase_16 AC 670 ms
394,072 KB
testcase_17 AC 669 ms
394,172 KB
testcase_18 AC 669 ms
394,264 KB
testcase_19 AC 670 ms
394,272 KB
testcase_20 AC 670 ms
394,272 KB
testcase_21 AC 672 ms
394,212 KB
testcase_22 AC 135 ms
83,608 KB
testcase_23 AC 270 ms
161,576 KB
testcase_24 AC 400 ms
239,616 KB
testcase_25 AC 533 ms
317,632 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