結果
問題 |
No.917 Make One With GCD
|
ユーザー |
![]() |
提出日時 | 2019-10-27 22:36:43 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 533 bytes |
コンパイル時間 | 1,975 ms |
コンパイル使用メモリ | 177,752 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-24 11:10:08 |
合計ジャッジ時間 | 2,860 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int64_t n; cin >> n; vector<int64_t> as(n); for (auto &&a : as) { cin >> a; } auto gcd = [](int64_t a, int64_t b) { while (b) { int64_t tmp = b; b = a % b; a = tmp; } return a; }; map<int64_t, int64_t> mp; mp[as[0]] = 1; for (int64_t i = 1; i < n; i++) { map<int64_t, int64_t> next(mp); next[as[i]]++; for (auto &&p : mp) { next[gcd(p.first, as[i])] += p.second; } swap(mp, next); } cout << mp[1] << endl; return 0; }