結果
| 問題 |
No.917 Make One With GCD
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-01-28 00:59:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 20 ms / 2,000 ms |
| コード長 | 1,199 bytes |
| コンパイル時間 | 2,157 ms |
| コンパイル使用メモリ | 206,872 KB |
| 最終ジャッジ日時 | 2025-02-10 07:26:15 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
using vi = vector <int>;
using ll = long long;
using vl = vector <ll>;
using pii = pair <int, int>;
//~ const ll mod = 998244353;
const ll mod = 1e9 + 7;
ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a;
for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; }
const int N = 55;
int a[N];
int mu(int x, set <int> ps) {
int r = 1;
for(int p : ps) {
int c = 0;
while(x % p == 0) {
x /= p;
c ++;
}
if(c >= 2) r = 0;
if(c == 1) r *= -1;
}
return r;
}
int main() {
ios :: sync_with_stdio(false);
int n; cin >> n;
map <int, int> mp;
for(int i = 1; i <= n; i ++) {
cin >> a[i];
set <int> ps;
int x = a[i];
for(int j = 2; j * j <= x; j ++) if(x % j == 0) {
ps.insert(j);
while(x % j == 0) x /= j;
}
if(x > 1) ps.insert(x);
x = a[i];
for(int j = 1; j * j <= x; j ++) if(x % j == 0) {
mp[j] = mu(j, ps);
mp[x / j] = mu(x / j, ps);
}
}
ll ans = 0;
for(auto [d, mu] : mp) {
int cnt = 0;
for(int i = 1; i <= n; i ++)
if(a[i] % d == 0)
cnt ++;
ans += mu * ((1LL << cnt) - 1);
}
cout << ans << '\n';
}