Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- /*
- * Author: Matheus Monteiro
- */
- using namespace std;
- // #ifdef DEBUGMONTEIRO
- #define _ << " , " <<
- #define bug(x) cout << #x << " >>>>>>> " << x << endl;
- // #else
- // #define bug(x)
- // #endif
- #define int long long
- #define Max(a, b) (a > b ? a : b)
- #define Min(a, b) (a < b ? a : b)
- #define ii pair<int, int>
- #define f first
- #define s second
- #define vi vector<int>
- #define vii vector<ii>
- #define LSOne(S) ((S) & (-S))
- #define UNTIL(t) while (clock() < (t) * CLOCKS_PER_SEC)
- #define SZ(a) (int)a.size()
- #define fastio std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
- const int MAX = 500000; //2 * 10^5
- const int mod = 1000000007; //10^9 + 7
- const int OO = 0x3f3f3f3f;//3f3f3f3f;
- const double EPS = 1e-9; //10^-9
- std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
- void solve() {
- int n, x;
- cin >> n >> x;
- vector<int> v(n);
- for(int &w : v) cin >> w;
- sort(v.begin(), v.end());
- v.resize(unique(v.begin(), v.end()) - v.begin());
- int ans = 0;
- for(int mask = 1; mask < (1 << v.size()); ++mask) {
- int sign = -1;
- int p = -1;
- for(int j = 0; j < v.size(); ++j) {
- if(mask & (1 << j)) {
- if(p == -1) p = v[j];
- else p = (p * v[j] / __gcd(p, v[j]));
- if((x / p) == 0) break;
- sign *= -1;
- }
- }
- ans = (x / p) * sign + ans;
- }
- cout << ans << '\n';
- }
- int32_t main() {
- fastio;
- int t = 1;
- // std::cin >> t;
- for(int caso = 1; caso <= t; ++caso) {
- // cout << "Case #" << caso << ": ";
- solve();
- }
- return 0;
- }
- /*
- Before submit:
- Check the corners cases
- Check solution restrictions
- For implementation solutions:
- Check the flow of the variables
- For intervals problems:
- Think about two pointers
- For complete search:
- Think about cuts
- If you get WA:
- Reread your code looking for stupid typos
- Try various manual testcases
- Recheck the correctness of your algorithm
- Reread the statement
- Write a straightforward solution, create lots of testcases by yourself, and compare both solutions
- Generate random test cases and perform a stress test, comparing your solution with the one that you are sure is correct
- Change the coder (if you're with a team)
- Give up. You may have other tasks to solve.
- */
Advertisement
Advertisement