Advertisement
Manioc

quase primos

Aug 2nd, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long ll;
  5. typedef pair<ll, ll> pii;
  6.  
  7. vector<ll> primes;
  8. ll ans, number;
  9.  
  10. void count(int idx = -1,ll val = 1, int cnt = 1){
  11.     if(val > number) return;
  12.  
  13.     if(cnt%2 == 0) ans -= (number/val);
  14.     else ans += (number/val);
  15.     for(int i = idx+1; i < primes.size(); i++){
  16.         count(i, val*primes[i],cnt+1);
  17.     }
  18. }
  19. int main(){
  20.     int k; cin >> number >> k;
  21.     for(int i = 0; i < k; i++){
  22.         int aux; cin >> aux;
  23.         primes.push_back(aux);
  24.     }
  25.     ans = 0;
  26.     count();
  27.     cout << ans << endl;
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement