結果
| 問題 |
No.1746 Sqrt Integer Segments
|
| ユーザー |
|
| 提出日時 | 2022-07-24 10:26:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 473 ms / 2,000 ms |
| コード長 | 2,921 bytes |
| コンパイル時間 | 2,219 ms |
| コンパイル使用メモリ | 211,876 KB |
| 最終ジャッジ日時 | 2025-01-30 13:30:47 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 |
ソースコード
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;
}