Advertisement
fooker

prime_multiples

May 12th, 2023
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int main()
  5. {
  6.     ll n,k;
  7.     cin>>n>>k;
  8.     ll a[k+1];
  9.     for (ll i=1; i<=k; i++) cin>>a[i];
  10.     vector<pair<ll,ll>> v,res;
  11.     v.push_back({a[1],-1});
  12.     for (ll i=2; i<=k; i++){
  13.         for (auto u:v){
  14.             res.push_back({(u.first)*a[i],(u.second)*(-1)});
  15.         }
  16.         v.push_back({a[i],-1});
  17.         for (auto u:res){
  18.             v.push_back({u.first,u.second});
  19.         }
  20.         res.clear();
  21.     }
  22.     ll ans=0;
  23.     for (auto u:v){
  24.         ans=ans-(n/u.first)*(u.second);
  25.     }
  26.     cout<<ans;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement