Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define endl '\n'
  5. #define db(x) cerr << #x << " == " << x << endl
  6. #define dbs(x) cerr << x << endl
  7. #define st first
  8. #define nd second
  9. #define pb push_back
  10. #define mp make_pair
  11. #define inf 0x3f3f3f3f
  12. #define linf 0x3f3f3f3f3f3f3f3f
  13.  
  14. typedef long long ll;
  15. typedef pair <int, int> pii;
  16. typedef vector <int> vi;
  17.  
  18. ll gcd(ll a, ll b){
  19.   return b ? gcd(b, a%b) : a ;
  20. }
  21.  
  22. int main(){
  23.   ios_base::sync_with_stdio(0);
  24.   cin.tie(0);
  25.   int n;
  26.   unordered_set<ll> ans;
  27.   set<ll> d;
  28.   cin >> n;
  29.   while(n--) {
  30.     ll x; cin >> x;
  31.     for(auto it=d.begin(); it!=d.end(); ){
  32.       ll g=gcd(*it, x);
  33.       it=d.erase(it);
  34.       d.insert(g);
  35.       ans.insert(g);
  36.     }
  37.     d.insert(x);
  38.     ans.insert(x);
  39.   }
  40.   cout << ans.size() << endl;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement