Advertisement
matheus_monteiro

H - How Many Laughs

Dec 10th, 2022
1,133
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2.  
  3. /*
  4.  * Author: Matheus Monteiro
  5.  */
  6.  
  7. using namespace std;
  8.  
  9. // #ifdef DEBUGMONTEIRO
  10. #define _ << " , " <<
  11. #define bug(x) cout << #x << "  >>>>>>>  " << x << endl;
  12. // #else
  13. // #define bug(x)
  14. // #endif
  15.  
  16. #define int long long
  17. #define Max(a, b) (a > b ? a : b)
  18. #define Min(a, b) (a < b ? a : b)
  19. #define ii pair<int, int>
  20. #define f first
  21. #define s second
  22. #define vi vector<int>
  23. #define vii vector<ii>
  24. #define LSOne(S) ((S) & (-S))
  25. #define UNTIL(t) while (clock() < (t) * CLOCKS_PER_SEC)
  26. #define SZ(a) (int)a.size()
  27. #define fastio std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
  28.  
  29. const int MAX = 500000; //2 * 10^5
  30. const int mod = 1000000007; //10^9 + 7
  31. const int OO = 0x3f3f3f3f;//3f3f3f3f;
  32. const double EPS = 1e-9;  //10^-9
  33. std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
  34.  
  35. void solve() {
  36.     int n, x;
  37.     cin >> n >> x;
  38.  
  39.     vector<int> v(n);
  40.     for(int &w : v) cin >> w;
  41.  
  42.     sort(v.begin(), v.end());
  43.     v.resize(unique(v.begin(), v.end()) - v.begin());
  44.    
  45.     int ans = 0;
  46.    
  47.     for(int mask = 1; mask < (1 << v.size()); ++mask) {
  48.         int sign = -1;
  49.         int p = -1;
  50.         for(int j = 0; j < v.size(); ++j) {
  51.             if(mask & (1 << j)) {
  52.                 if(p == -1) p = v[j];
  53.                 else p = (p * v[j] / __gcd(p, v[j]));
  54.                 if((x / p) == 0) break;
  55.                 sign *= -1;
  56.             }
  57.         }  
  58.         ans = (x / p) * sign + ans;
  59.     }
  60.  
  61.     cout << ans << '\n';
  62. }
  63.  
  64. int32_t main() {
  65.     fastio;
  66.  
  67.     int t = 1;
  68.     // std::cin >> t;
  69.  
  70.     for(int caso = 1; caso <= t; ++caso) {
  71.         // cout << "Case #" << caso << ": ";
  72.         solve();
  73.     }
  74.  
  75.     return 0;
  76. }
  77.  
  78. /*
  79. Before submit:
  80.     Check the corners cases
  81.     Check solution restrictions
  82.  
  83. For implementation solutions:
  84.     Check the flow of the variables
  85.  
  86. For intervals problems:
  87.     Think about two pointers
  88.  
  89. For complete search:
  90.     Think about cuts
  91.  
  92. If you get WA:
  93.     Reread your code looking for stupid typos
  94.     Try various manual testcases
  95.     Recheck the correctness of your algorithm
  96.     Reread the statement
  97.     Write a straightforward solution, create lots of testcases by yourself, and compare both solutions
  98.     Generate random test cases and perform a stress test, comparing your solution with the one that you are sure is correct
  99.     Change the coder (if you're with a team)
  100.     Give up. You may have other tasks to solve.
  101. */
  102.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement