結果
問題 | No.917 Make One With GCD |
ユーザー |
![]() |
提出日時 | 2019-10-25 23:04:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,203 bytes |
コンパイル時間 | 2,063 ms |
コンパイル使用メモリ | 181,996 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-24 11:05:50 |
合計ジャッジ時間 | 3,141 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define int long long#define REP(i,n) for(int i = 0;i < (int)(n);i++)#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)#define FOR(i,s,n) for(int i = s;i < (int)n;i++)#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)#define ALL(a) a.begin(),a.end()template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}constexpr long long INF = 1e18;vector<pair<long long, long long> > prime_factorize(long long n) {//計算量は√N!!!vector<pair<long long, long long> > res;for (long long p = 2; p * p <= n; ++p) {if (n % p != 0) continue;int num = 0;while (n % p == 0) { ++num; n /= p; }res.push_back(make_pair(p, num));}if (n != 1) res.push_back(make_pair(n, 1));return res;}int gcd(int x,int y){if(x==0) return y;return gcd(y%x,x);}int lcm(int x, int y){return (x * y / gcd(x, y));}signed main(){int N;cin>>N;vector<int> a(N); for(auto& e:a)cin >> e;map<int,int>dp;dp[a[0]]=1;FOR(i,1,N){for(auto e:dp){dp[gcd(e.first,a[i])]+=e.second;}dp[a[i]]++;}cout<<dp[1]<<endl;}