結果
| 問題 |
No.917 Make One With GCD
|
| コンテスト | |
| ユーザー |
iqueue02
|
| 提出日時 | 2020-02-21 17:13:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 619 bytes |
| コンパイル時間 | 1,653 ms |
| コンパイル使用メモリ | 179,664 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-24 11:14:14 |
| 合計ジャッジ時間 | 2,681 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
int main(){
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
auto GCD = [&](auto& f, int a, int b) -> int{
if (b == 0) return a;
return f(f,b,a%b);
};
vector<map<int, ll>> dp(n);
ll res = 0;
for (int i = 0; i < n; i++) {
dp[i][a[i]]++;
for (int j = i + 1; j < n; j++) {
for (auto e : dp[i]) dp[j][GCD(GCD, a[j], e.first)] += e.second;
}
res += dp[i][1];
}
cout << res << endl;
return 0;
}
iqueue02