結果
| 問題 |
No.917 Make One With GCD
|
| コンテスト | |
| ユーザー |
どらら
|
| 提出日時 | 2019-10-26 01:43:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 1,394 bytes |
| コンパイル時間 | 1,861 ms |
| コンパイル使用メモリ | 185,132 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-24 11:08:00 |
| 合計ジャッジ時間 | 2,855 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
vector<int> divisor(int n){
vector<int> ret;
for(int i=1; i*i<=n; i++){
if(n%i==0){
ret.push_back(i);
if(i!=n/i) ret.push_back(n/i);
}
}
//sort(ret.begin(), ret.end());
return ret;
}
int gcd(int a, int b){return (b==0?a:gcd(b,a%b));}
int main(){
int N;
cin >> N;
vector<ll> v;
map<int,int> memo;
rep(i,N){
ll a;
cin >> a;
v.push_back(a);
vector<int> div = divisor(a);
rep(j,div.size()){
memo[div[j]] = 1;
}
}
map<int,int> inv;
vector<int> w;
FOR(it,memo){
w.push_back(it->first);
inv[it->first] = w.size()-1;
}
vector<vector<ll>> dp(N+1, vector<ll>(w.size(), 0));
rep(i,N){
int a = v[i];
rep(j,w.size()){
int b = w[j];
dp[i+1][j] += dp[i][j];
if(dp[i][j] > 0){
dp[i+1][inv[gcd(a,b)]] += dp[i][j];
}
}
dp[i+1][inv[a]]++;
}
/*
rep(i,dp.size()){
rep(j,dp[i].size()){
cout << dp[i][j] << " ";
}
cout << endl;
}
*/
ll ret = 0;
REP(i,1,dp[N].size()) ret += dp[N][i];
cout << (1LL<<N)-1-ret << endl;
return 0;
}
どらら