Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define TIME cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
- using namespace std;
- const int N = 100005;
- bitset<N> possible, temp, there, lst;
- int main(){
- int t=1;
- while(t--){
- int n, x; scanf("%d %d", &n, &x);
- int mn = INT_MAX;
- there.reset(); possible.reset(); lst.set();
- for(int i = 0; i < n; i++){
- int y; scanf("%d", &y);
- mn = min(mn, y);
- there[y] = 1;
- possible[x % y] = 1;
- }
- for(int v = N - 1; v >= 1; v--){
- lst.reset(v);
- if(!there[v]) continue;
- // N/64 * log(N / V) calculations
- temp = possible;
- for(int j = 0; (1<<j) * v < N; j++) temp |= temp >> ((1 << j) * v);
- possible |= (temp & lst);
- }
- // Using log(N!) ~ N logN - N,
- // It can be proved that sum_{v=1}^{N} log(N / v) ~ N logN - (N logN - N) ~ N.
- // So, total bitset operations ~ N.
- there.reset();
- for(int i = 0; i < N; i++) if(possible[i]) there[i % mn] = 1;
- printf("%d\n", (int)there.count());
- }
- TIME
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement