結果
問題 | No.917 Make One With GCD |
ユーザー |
|
提出日時 | 2019-09-13 14:11:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 526 bytes |
コンパイル時間 | 834 ms |
コンパイル使用メモリ | 82,832 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-24 11:02:38 |
合計ジャッジ時間 | 2,013 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
#include <iostream> #include <vector> #include <map> using namespace std; using ll = long long; template<typename T> T gcd_(T a, T b) { while (b) { T tmp = b; b = a % b; a = tmp; } return a; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; map<int, ll> dp; for (int x : a) { for (auto& p : dp) { dp[gcd_(p.first, x)] += p.second; } dp[x]++; } cout << dp[1] << endl; return 0; }