結果
問題 |
No.917 Make One With GCD
|
ユーザー |
|
提出日時 | 2021-07-13 23:36:59 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 936 bytes |
コンパイル時間 | 1,162 ms |
コンパイル使用メモリ | 104,048 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-02 18:55:05 |
合計ジャッジ時間 | 2,269 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <iomanip> #include <cmath> #include <stdio.h> #include <queue> #include <deque> #include <cstdio> #include <set> #include <map> #include <bitset> #include <stack> #include <cctype> using namespace std; #define int long long long long gcd(long long a, long long b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } long long dp[10010] = {}; map<int, int> m; set<int> st; int a[55]; signed main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { for (auto j = st.begin(); j != st.end(); j++) { int g = gcd(*j, a[i]); m[g] += m[*j]; st.insert(g); } m[a[i]]++; st.insert(a[i]); } long long ans = 1; for (int i = 0; i < n; i++) { ans *= 2; } ans--; for (auto j = st.begin(); j != st.end(); j++) { if (*j != 1)ans -= m[*j]; } cout << ans << endl; }