結果
問題 |
No.917 Make One With GCD
|
ユーザー |
|
提出日時 | 2020-04-26 13:20:30 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 934 bytes |
コンパイル時間 | 1,095 ms |
コンパイル使用メモリ | 83,056 KB |
最終ジャッジ日時 | 2025-01-10 01:56:30 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 TLE * 11 |
ソースコード
#include <iostream> #include <numeric> #include <vector> #include <map> using lint = long long; std::map<int, lint> count(int n) { std::vector<int> xs(n); for (auto& x : xs) std::cin >> x; std::map<int, lint> ret; for (int b = 0; b < (1 << n); ++b) { lint g = 0; for (int i = 0; i < n; ++i) { if ((b >> i) & 1) g = std::gcd(g, xs[i]); } if (!ret.count(g)) ret[g] = 0; ++ret[g]; } return ret; } void solve() { int n; std::cin >> n; auto fore = count(n / 2), back = count(n - n / 2); lint ans = 0; for (auto p : fore) { for (auto q : back) { if (std::gcd(p.first, q.first) == 1) { ans += p.second * q.second; } } } std::cout << ans << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }