結果

問題 No.917 Make One With GCD
ユーザー kibunakibuna
提出日時 2019-10-26 01:25:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 2,077 bytes
コンパイル時間 1,834 ms
コンパイル使用メモリ 180,624 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 16:42:37
合計ジャッジ時間 3,074 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 15 ms
4,376 KB
testcase_07 AC 10 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 15 ms
4,376 KB
testcase_10 AC 16 ms
4,380 KB
testcase_11 AC 14 ms
4,380 KB
testcase_12 AC 18 ms
4,376 KB
testcase_13 AC 12 ms
4,376 KB
testcase_14 AC 14 ms
4,376 KB
testcase_15 AC 15 ms
4,376 KB
testcase_16 AC 13 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 8 ms
4,376 KB
testcase_24 AC 5 ms
4,376 KB
testcase_25 AC 9 ms
4,376 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

template <typename T = int>
void primeFactors(T a, map<T, int> &facs) {
    double sqrtA = sqrt(a);
    for (int i = 2; i <= sqrtA + 1e-10; ++i) {
        while (a % i == 0) {
            facs[i]++;
            a /= i;
        }
    }
    if (a > sqrtA)
        facs[a]++;
    return;
}

// list up all factors
template <typename T>
set<T> factors(T a) {
    set<T> facs;
    for (T i = 1; i * i <= a; ++i) {
        if (a % i == 0) {
            facs.insert(i);
            facs.insert(a / i);
        }
    }
    return facs;
}

int main() {
    int n;
    cin >> n;
    vl a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    map<ll, int> facs;
    for (int i = 0; i < n; ++i) {
        auto fac = factors(a[i]);
        for (auto &f : fac) {
            facs[f]++;
        }
    }
    ll ret = 1;
    for (int i = 0; i < n; ++i) {
        ret *= 2;
    }
    ret -= 1; // empty set
    for (auto &p : facs) {
        if (p.first == 1)
            continue;
        ll temp = 1;
        for (int i = 0; i < p.second; ++i) {
            temp *= 2;
        }
        temp--;
        map<ll, int> primefac;
        primeFactors(p.first, primefac);
        for (auto &pp : primefac) {
            if (pp.second > 1) {
                temp = 0;
            }
        }
        temp *= int(primefac.size()) % 2 == 0 ? -1 : 1;
        ret -= temp;
    }
    cout << ret << "\n";
    return 0;
}
0