题意:同【HDU】1796 How many integers can you find。
1 #include<cstdio> 2 #include<algorithm> 3 typedef long long LL; 4 #define MAXN 110 5 using namespace std; 6 int m; 7 LL n, ans; 8 int a[MAXN]; 9 LL GCD(LL x, LL y) { 10 return y ? GCD(y, x % y) : x; 11 } 12 LL LCM(LL x, LL y) { 13 return x / GCD(x, y) * y; 14 } 15 LL Get(int x, int &cnt) { 16 int i; 17 LL res = 1; 18 for (i = cnt = 0; i < m; i++) { 19 if (x & (1 << i)) { 20 cnt++; 21 res = LCM(res, a[i]); 22 } 23 } 24 return res; 25 } 26 int main() { 27 int i, k; 28 LL tmp; 29 while (~scanf("%d%lld", &m, &n)) { 30 for (ans = i = 0; i < m; i++) 31 scanf("%d", &a[i]); 32 for (i = 1; i < (1 << m); i++) { 33 tmp = Get(i, k); 34 if (k & 1) 35 ans += n / tmp; 36 else 37 ans -= n / tmp; 38 } 39 printf("%lld\n", ans); 40 } 41 return 0; 42 }