結果

問題 No.917 Make One With GCD
ユーザー 👑 emthrmemthrm
提出日時 2019-10-25 22:46:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,208 bytes
コンパイル時間 2,576 ms
コンパイル使用メモリ 133,740 KB
実行使用メモリ 8,744 KB
最終ジャッジ日時 2023-10-11 07:09:47
合計ジャッジ時間 5,257 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
vector<long long> divisor(long long val) {
  vector<long long> res;
  for (long long i = 1; i * i <= val; ++i) {
    if (val % i == 0) {
      res.emplace_back(i);
      if (i * i != val) res.emplace_back(val / i);
    }
  }
  sort(ALL(res));
  res.erase(res.begin());
  return res;
}

bool is_prime(long long val) {
  if (val <= 1) return false;
  for (long long i = 2; i * i <= val; ++i) {
    if (val % i == 0) return false;
  }
  return true;
}

int main() {
  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];
  set<int> st;
  REP(i, n) {
    auto d = divisor(a[i]);
    for (int e : d) st.emplace(e);
  }
  vector<int> primes;
  for (int e : st) {
    if (is_prime(e)) primes.emplace_back(e);
  }
  int m = primes.size();
  long long ans = 0;
  REP(i, 1 << m) {
    long long now = 1;
    REP(j, m) {
      if (i >> j & 1) now *= primes[j];
    }
    int cnt = 0;
    REP(j, n) {
      if (a[j] % now == 0) ++cnt;
    }
    if (__builtin_popcount(i) % 2 == 0) {
      ans += (1LL << cnt) - 1;
    } else {
      ans -= (1LL << cnt) - 1;
    }
  }
  cout << ans << '\n';
  return 0;
}
0