結果
問題 | No.917 Make One With GCD |
ユーザー |
![]() |
提出日時 | 2019-10-26 00:09:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 937 bytes |
コンパイル時間 | 1,070 ms |
コンパイル使用メモリ | 89,008 KB |
最終ジャッジ日時 | 2025-01-08 01:48:39 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
#include <iostream> #include <set> #include <map> using namespace std; typedef long long ll; set<int> s; map<int,ll> mp; map<int,int> mb; ll pw(ll a, ll x){ ll ret = 1; while(x){ while(!(x&1)){ (a *= a); x /= 2; } ret *= a; x--; } return ret; } void meb(int x){ map<int,int> m; int i,z = x; for(i=2;i*i<=x;i++){ while(x%i==0){ m[i]++; x /= i; } } if(x!=1) m[x]++; for(auto y:m){ if(y.second>1){ mb[z] = 0; return ; } } if((int)m.size()&1) mb[z] = -1; else mb[z] = 1; } int a[110]; int main(){ int i,j,n; cin >> n; for(i=0;i<n;i++){ cin >> a[i]; for(j=1;j*j<=a[i];j++){ if(a[i]%j==0){ s.insert(j); s.insert(a[i]/j); } } } s.erase(1); for(auto x:s){ int sum = 0; for(i=0;i<n;i++){ if(a[i]%x==0) sum++; } meb(x); mp[x] = pw(2,sum) - 1; } long long ans = pw(2,n) - 1; for(auto x:mp){ int y = x.first; ans += mb[y]*mp[y]; } cout << ans << endl; }