daily pastebin goal
20%
SHARE
TWEET

Untitled

a guest Jul 12th, 2018 65 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. typedef long long ll;
  5. ll n, k;
  6.  
  7. ll mdc(ll a, ll b){
  8.     if(!b) return a;
  9.     return mdc(b, a % b);
  10. }
  11.  
  12. ll mmc(ll a, ll b){
  13.     return a*b/mdc(a, b);
  14. }
  15.  
  16. int main(int argc, char const *argv[])
  17. {
  18.     scanf("%lld %lld", &n, &k);
  19.     vector<ll> v(k);
  20.     for(int i = 0; i < k; i++)
  21.         scanf("%lld", &v[i]);
  22.  
  23.     ll ans = 0;
  24.     for(int b = 1; b < (1 << k); b++){
  25.         vector<ll> a;
  26.         for(int i = 0; i < k; i++)
  27.             if(b & (1 << i))
  28.                 a.push_back(v[i]);
  29.  
  30.         ll x = 1;
  31.         for(int i = 0; i < a.size(); i++)
  32.             x = mmc(x, a[i]);
  33.         if(a.size() % 2)
  34.             ans += n/x;
  35.         else
  36.             ans -= n/x;
  37.     }
  38.  
  39.     printf("%lld\n", n - ans);
  40.  
  41.     return 0;
  42. }
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