#include #include template struct Mobius { std::array mobius; Mobius() : mobius{} { mobius[1] = 1; std::array sieve; sieve.fill(1); for (int p = 2; p <= M; ++p) if (sieve[p]) { for (int v = M / p, vp = v * p; v; --v, vp -= p) { mobius[vp] = -mobius[v], sieve[vp] = false; } } } int operator[](int i) const { return mobius[i]; } }; constexpr int M = 1000000; constexpr int MAX_LOG2 = 39, MAX_LOG3 = 25; long long count_square_2_3_free(long long n) { static Mobius mobius; const int q = std::sqrt(n); long long res = 0; for (int i = 1; i <= q; i += 6) if (mobius[i]) { double d = n / (double(i) * i); long long v1 = (d + 1) / 6; long long v5 = (d + 5) / 6; res += mobius[i] * (v1 + v5); } for (int i = 5; i <= q; i += 6) if (mobius[i]) { double d = n / (double(i) * i); long long v1 = (d + 1) / 6; long long v5 = (d + 5) / 6; res += mobius[i] * (v1 + v5); } return res; } #include int main() { long long l; int n; std::cin >> l >> n; std::array, MAX_LOG2 + 2> cnt{}; for (int i = 0; i < n; ++i) { long long x; std::cin >> x; int e2 = 0, e3 = 0; for (long long v = x; v % 2 == 0; v /= 2) ++e2; for (long long v = x; v % 3 == 0; v /= 3) ++e3; for (int f : { 0, 1 }) for (int g : { 0, 1 }) cnt[e2 + f][e3 + g] ^= 1; } long long ans = 0; long long p2 = 1; for (int e2 = 0; e2 <= MAX_LOG2; ++e2, p2 *= 2) { long long p3 = 1; for (int e3 = 0; e3 <= MAX_LOG3; ++e3, p3 *= 3) { if (cnt[e2][e3]) ans += count_square_2_3_free(l / (p2 * p3)); } } std::cout << ans << '\n'; }