Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 6th, 2020 298 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top