結果
| 問題 |
No.917 Make One With GCD
|
| コンテスト | |
| ユーザー |
emthrm
|
| 提出日時 | 2019-10-25 23:02:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,583 bytes |
| コンパイル時間 | 3,221 ms |
| コンパイル使用メモリ | 135,404 KB |
| 最終ジャッジ日時 | 2025-01-08 01:38:48 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 WA * 10 TLE * 4 |
ソースコード
#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);
}
set<long long> v;
for (int e : st) {
if (is_prime(e)) {
long long tmp = 0;
REP(i, n) {
if (a[i] % e == 0) tmp |= 1LL << i;
}
v.emplace(tmp);
}
}
vector<long long> vec;
while (!v.empty()) {
long long now = *v.begin();
v.erase(now);
bool exist = false;
for (long long e : v) {
if (now & e == now) {
exist = true;
break;
}
}
if (!exist) vec.emplace_back(now);
}
int m = vec.size();
long long ans = (1LL << n) - 1;
FOR(i, 1, 1 << m) {
long long now = (1LL << n) - 1;
REP(j, m) {
if (i >> j & 1) now &= vec[j];
}
if (__builtin_popcount(i) & 1) {
ans -= (1LL << (__builtin_popcount(now))) - 1;
} else {
ans += (1LL << (__builtin_popcount(now))) - 1;
}
}
cout << ans << '\n';
return 0;
}
emthrm