fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3.  
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6.  
  7. typedef long long ll;
  8.  
  9. gp_hash_table<ll, bool> HASH;
  10. int n;
  11. unordered_set<ll> seen;
  12. ll m, x;
  13. vector<ll> a;
  14.  
  15. int main() {
  16. ios_base::sync_with_stdio(false);
  17. cin.tie(NULL);
  18. cin >> n >> m;
  19.  
  20. ll k = min(m, 18000LL);
  21.  
  22. for(int i = 1; i <= n; i++) {
  23. cin >> x;
  24. if(x == 1) {
  25. cout << 0;
  26. return 0;
  27. }
  28. if(seen.count(x) == 0) {
  29. seen.insert(x);
  30. a.push_back(x);
  31. }
  32. }
  33.  
  34. for(int i = 0; i < a.size(); i++) {
  35. if(HASH.find(a[i]) != HASH.end()) continue;
  36. for(ll j = 1; j <= k / a[i]; j++) {
  37. HASH[a[i] * j] = true;
  38. }
  39. }
  40.  
  41. ll res = k - HASH.size();
  42. if(m > k) {
  43. res += m / 18000;
  44. m %= 18000;
  45.  
  46. HASH.clear();
  47.  
  48. for(int i = 0; i < a.size(); i++) {
  49. if(HASH.find(a[i]) != HASH.end()) continue;
  50. for(ll j = 1; j <= m / a[i]; j++) {
  51. HASH[a[i] * j] = true;
  52. }
  53. }
  54.  
  55. res += m - HASH.size();
  56. }
  57.  
  58. cout << res;
  59.  
  60. return 0;
  61. }
Success #stdin #stdout 0.01s 5304KB
stdin
2 10
2 3
stdout
3