結果

問題 No.1514 Squared Matching
ユーザー zhanghonghe2
提出日時 2021-06-26 01:36:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 754 bytes
コンパイル時間 957 ms
コンパイル使用メモリ 67,168 KB
最終ジャッジ日時 2025-01-22 13:01:44
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 TLE * 14 MLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int maxn=5e7+10;
int p[maxn];
int cnt[maxn];

void init(int N){
    p[1]=1;
    for(int i=2;i<=N;i++){
        if(p[i]==0) {
            for (int j = i; j <= N; j += i) {
                p[j] = i;
            }
        }
    }
}


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

    

    int ans=0;
    for(int x=1;x<=N;x++){
        ans+=1;//ans+=(x,x)

        int K=x;
        int hash=1;
        while(K!=1){
            if(hash%p[K]==0){
                hash/=p[K];
            }else{
                hash*=p[K];
            }
            K/=p[K];
        }

        ans+=cnt[hash]*2;
        cnt[hash]+=1;
    }
    cout<<ans<<endl;
    return 0;
}
0