結果
| 問題 |
No.917 Make One With GCD
|
| コンテスト | |
| ユーザー |
ei13337
|
| 提出日時 | 2019-10-25 22:39:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,241 bytes |
| コンパイル時間 | 1,829 ms |
| コンパイル使用メモリ | 180,568 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-13 05:06:43 |
| 合計ジャッジ時間 | 2,972 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 WA * 14 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll mod = 1000000007;
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
set<int> s;
vector<int> d;
s.insert(1);
rep(i, n) {
for(int j = 1; j * j <= a[i]; j++) {
if(a[i] % j == 0) {
if(!s.count(j)) {
s.insert(j);
d.push_back(j);
}
if(!s.count(a[i] / j)) {
s.insert(a[i] / j);
d.push_back(a[i] / j);
}
}
}
}
sort(d.begin(), d.end());
reverse(d.begin(), d.end());
int m = (int)d.size();
vector<ll> dp(m, 0);
ll ans = (1LL << n) - 1;
rep(i, m) {
int c = 0;
rep(j, n) if(a[j] % d[i] == 0) c++;
dp[i] = (1LL << c) - 1; dp[i] %= mod;
for(int j = 0; j < i; j++) {
if(d[j] % d[i] == 0) {
dp[i] -= dp[j];
dp[i] += mod; dp[i] %= mod;
}
}
ans -= dp[i];
ans += mod; ans %= mod;
}
cout << ans << endl;
return 0;
}
ei13337