結果
問題 | No.917 Make One With GCD |
ユーザー |
![]() |
提出日時 | 2019-10-25 23:04:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 2,793 bytes |
コンパイル時間 | 1,926 ms |
コンパイル使用メモリ | 183,784 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-24 11:05:35 |
合計ジャッジ時間 | 2,813 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long signed int LL;typedef long long unsigned int LU;#define incID(i, l, r) for(LL i = (l) ; i < (r); ++i)#define incII(i, l, r) for(LL i = (l) ; i <= (r); ++i)#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)#define decII(i, l, r) for(LL i = (r) ; i >= (l); --i)#define inc(i, n) incID(i, 0, n)#define inc1(i, n) incII(i, 1, n)#define dec(i, n) decID(i, 0, n)#define dec1(i, n) decII(i, 1, n)#define inID(v, l, r) ((l) <= (v) && (v) < (r))#define inII(v, l, r) ((l) <= (v) && (v) <= (r))#define PB push_back#define EB emplace_back#define MP make_pair#define FI first#define SE second#define ALL(v) v.begin(), v.end()#define RALL(v) v.rbegin(), v.rend()template<typename T> bool setmin (T & a, T b) { if(b < a) { a = b; return true; } else { return false; } }template<typename T> bool setmax (T & a, T b) { if(b > a) { a = b; return true; } else { return false; } }template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }#define bit(b, i) (((b) >> (i)) & 1)#define BC __builtin_popcountll#define SC static_cast#define SI(v) SC<int>(v.size())#define SL(v) SC<LL >(v.size())#define RF(e, v) for(auto & e: v)#define ef else if#define UR assert(false)// ---- ----vector<pair<LL, LL>> prime_factorization(LL x) {assert(x > 0);vector<pair<LL, LL>> f;for(LL i = 2; i <= x; i++) {if(i * i > x) { i = x; }if(x % i == 0) {f.EB(i, 0);while(x % i == 0) { f.back().SE++; x /= i; }}}return f;}vector<LL> divisors(LL x) {auto pf = prime_factorization(x);vector<LL> d = { 1 };for(auto e: pf) {int ds = d.size();inc(i, ds) {LL v = d[i];inc(j, e.SE) { v *= e.FI; d.PB(v); }}}sort(ALL(d));return d;}#define UQwoS(v) v.erase(unique(ALL(v)), v.end())#define UQ(v) sort(ALL(v)); UQwoS(v)int n, a[50];int main() {cin >> n;inc(i, n) { cin >> a[i]; }vector<int> v;inc(i, n) {auto d = divisors(a[i]);RF(e, d) { v.PB(e); }}UQ(v);vector<LL> dp(SI(v));dec(i, SI(v)) {LL c = 0;inc(j, n) { if(a[j] % v[i] == 0) { c++; } }dp[i] = (1LL << c) - 1;decID(j, i + 1, SI(v)) { if(v[j] % v[i] == 0) { dp[i] -= dp[j]; } }}cout << dp[0] << endl;return 0;}