1717
思路:
m-=17之后容斥就好了。
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define LL long long
using namespace std;
int n;
LL m, ans = 1, a[510];
LL gcd(LL a, LL b){
if(b == 0) return a;
return gcd(b, a%b);
}
LL lcm(LL a, LL b){
return a / gcd(a, b) * b;
}
void dfs(int step, LL L, int flag ) {
if(L>m || step==n) return;
LL LCM = lcm(L, a[step]);
ans += flag * (m / LCM);
dfs(step+1, L, flag);
dfs(step+1, LCM, -flag);
}
int main(){
cin >> n >> m;
if(m <= 17) return puts("0"), 0;
m -= 17;
for(int i=0; i<=n-1; ++i)
cin >> a[i];
dfs(0, 1LL, 1);
cout << ans << endl;
}