結果

問題 No.1514 Squared Matching
ユーザー sgswsgsw
提出日時 2021-05-23 01:13:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,790 ms / 4,000 ms
コード長 1,498 bytes
コンパイル時間 2,051 ms
コンパイル使用メモリ 199,440 KB
実行使用メモリ 400,128 KB
最終ジャッジ日時 2024-04-19 08:55:49
合計ジャッジ時間 76,038 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,631 ms
399,940 KB
testcase_01 AC 2,714 ms
399,980 KB
testcase_02 AC 2,618 ms
400,016 KB
testcase_03 AC 2,633 ms
399,900 KB
testcase_04 AC 2,688 ms
399,928 KB
testcase_05 AC 2,637 ms
399,896 KB
testcase_06 AC 2,635 ms
400,040 KB
testcase_07 AC 2,638 ms
400,092 KB
testcase_08 AC 2,736 ms
399,968 KB
testcase_09 AC 2,723 ms
399,980 KB
testcase_10 AC 2,705 ms
400,096 KB
testcase_11 AC 2,705 ms
399,912 KB
testcase_12 AC 2,718 ms
400,036 KB
testcase_13 AC 2,742 ms
400,028 KB
testcase_14 AC 2,735 ms
399,920 KB
testcase_15 AC 2,790 ms
400,128 KB
testcase_16 AC 2,785 ms
400,040 KB
testcase_17 AC 2,739 ms
399,964 KB
testcase_18 AC 2,747 ms
399,912 KB
testcase_19 AC 2,726 ms
400,120 KB
testcase_20 AC 2,766 ms
400,068 KB
testcase_21 AC 2,745 ms
400,092 KB
testcase_22 AC 2,678 ms
399,916 KB
testcase_23 AC 2,676 ms
399,912 KB
testcase_24 AC 2,699 ms
400,124 KB
testcase_25 AC 2,727 ms
399,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

#define rep(i,n) for (int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1;i<=(n);i++)
#define rrep(i,n) for(int i = (n)-1;i>=0;i--)
#define rrep1(i, n) for (int i = (n); i > 0; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define ALL(a) a.begin(),a.end()
#define elif else if
#define foreach(elem,a) for (auto elem : a)
#define list vector

template<class T> ostream& operator << (ostream &s, vector<T> &P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }

template <class T>bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template <class T>bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}
template <class T = int>T gcd(T a, T b){return (b == 0) ? a : gcd(b, a % b);}
template <class T = int>T lcm(T a, T b){return a / gcd(a, b) * b;}
using P  = pair<int,int>;

const int MAXN = 50000010;

list<int> A(MAXN);
list<bool> isprime(MAXN,true);
list<int> CNT(MAXN,0);

void setup_init(){
    rep(i,MAXN){A[i]=i;}
    isprime[0] = isprime[1] = false;
    for (int i = 2; i < MAXN;i++){
        if (!isprime[i])continue;
        int sq = i*i;
        for (int j = 2*i; j < MAXN;j+=i){
            isprime[j]=false;
            while(A[j]%sq == 0){A[j]/=sq;}
        }
    }
}

signed main(){
    setup_init();
    int n;cin>>n;
    rep1(i,n){CNT[A[i]]++;}
    
    int ans = 0;
    rep1(i,n){
        ans += CNT[i]*CNT[i];
    }
    cout << ans << endl;
    return 0;
}
0