結果
問題 | No.917 Make One With GCD |
ユーザー |
![]() |
提出日時 | 2019-10-30 21:22:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 628 bytes |
コンパイル時間 | 944 ms |
コンパイル使用メモリ | 78,760 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-24 11:10:30 |
合計ジャッジ時間 | 1,738 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
#include <iostream> #include <map> using namespace std; typedef long long ll; ll gcd(ll a, ll b) { if(b == 0) return a; return gcd(b, a%b); } int main() { int n; cin >> n; ll a[n]; for(int i=0;i<n;++i){ cin >> a[i]; } map<ll, ll> mp[n]; mp[0][a[0]] = 1; ll ans = ((a[0] == 1) ? 1 : 0); for(int i=1;i<n;++i) { ++mp[i][a[i]]; for(int j=0;j<i;++j) { for(auto itr=mp[j].begin();itr!=mp[j].end();++itr) { mp[i][gcd(itr->first, a[i])] += itr->second; } } ans += mp[i][1]; } cout << ans << endl; }