結果

問題 No.1746 Sqrt Integer Segments
ユーザー erbowlerbowl
提出日時 2022-07-24 10:26:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 642 ms / 2,000 ms
コード長 2,921 bytes
コンパイル時間 2,357 ms
コンパイル使用メモリ 217,112 KB
実行使用メモリ 34,160 KB
最終ジャッジ日時 2023-09-20 08:37:22
合計ジャッジ時間 16,915 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 145 ms
19,632 KB
testcase_01 AC 141 ms
19,696 KB
testcase_02 AC 482 ms
30,448 KB
testcase_03 AC 313 ms
25,976 KB
testcase_04 AC 375 ms
27,580 KB
testcase_05 AC 621 ms
33,772 KB
testcase_06 AC 266 ms
24,284 KB
testcase_07 AC 177 ms
21,304 KB
testcase_08 AC 473 ms
29,776 KB
testcase_09 AC 627 ms
33,736 KB
testcase_10 AC 254 ms
23,996 KB
testcase_11 AC 571 ms
32,556 KB
testcase_12 AC 625 ms
34,160 KB
testcase_13 AC 639 ms
34,160 KB
testcase_14 AC 642 ms
33,980 KB
testcase_15 AC 641 ms
33,860 KB
testcase_16 AC 624 ms
33,912 KB
testcase_17 AC 409 ms
28,724 KB
testcase_18 AC 164 ms
19,820 KB
testcase_19 AC 163 ms
19,848 KB
testcase_20 AC 161 ms
19,832 KB
testcase_21 AC 184 ms
19,620 KB
testcase_22 AC 181 ms
19,704 KB
testcase_23 AC 158 ms
19,828 KB
testcase_24 AC 227 ms
19,580 KB
testcase_25 AC 229 ms
19,696 KB
testcase_26 AC 228 ms
19,760 KB
testcase_27 AC 269 ms
19,760 KB
testcase_28 AC 270 ms
19,580 KB
testcase_29 AC 272 ms
19,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
#define int long long


struct Eratos {
    vector<int> primes;
    vector<bool> isprime;
    vector<int> mebius;
    vector<int> min_factor;

    Eratos(int MAX) : primes(),
                      isprime(MAX+1, true),
                      mebius(MAX+1, 1),
                      min_factor(MAX+1, -1) {
        isprime[0] = isprime[1] = false;
        min_factor[0] = 0, min_factor[1] = 1;
        for (int i = 2; i <= MAX; ++i) {
            if (!isprime[i]) continue;
            primes.push_back(i);
            mebius[i] = -1;
            min_factor[i] = i;
            for (int j = i*2; j <= MAX; j += i) {
                isprime[j] = false;
                if ((j / i) % i == 0) mebius[j] = 0;
                else mebius[j] = -mebius[j];
                if (min_factor[j] == -1) min_factor[j] = i;
            }
        }
    }

    // prime factorization
    vector<pair<int,int>> prime_factors(int n) {
        vector<pair<int,int> > res;
        while (n != 1) {
            int prime = min_factor[n];
            int exp = 0;
            while (min_factor[n] == prime) {
                ++exp;
                n /= prime;
            }
            res.push_back(make_pair(prime, exp));
        }
        return res;
    }

    // enumerate divisors
    vector<int> divisors(int n) {
        vector<int> res({1});
        auto pf = prime_factors(n);
        for (auto p : pf) {
            int n = (int)res.size();
            for (int i = 0; i < n; ++i) {
                int v = 1;
                for (int j = 0; j < p.second; ++j) {
                    v *= p.first;
                    res.push_back(res[i] * v);
                }
            }
        }
        return res;
    }
};

// 整数値 x にハッシュ値を割り当てる関数
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator() (uint64_t x) const {
        static const uint64_t FIXED_RANDOM =    
            chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
} rng;


signed main(){
    ll n;
    Eratos er((ll)1e6+10);
    std::cin >> n;
    map<ll,ll> hashm;
    map<ll,ll> cnt;
    cnt[0]++;
    ll now = 0;
    for (int i = 0; i < n; i++) {
        ll a;
        std::cin >> a;
        auto vec = er.prime_factors(a);
        for (auto e : vec) {
            if(e.second%2==0)continue;
            if(hashm[e.first]==0){
                hashm[e.first] = rng(e.first);
            }
            now ^= hashm[e.first];
        }
        cnt[now]++;
    }
    ll ans = 0;
    for (auto e : cnt) {
        ans += e.second*(e.second-1)/2;
    }
    std::cout << ans << std::endl;
}
0