boolcheck(int x) { for (int i = 1; i <= n; i++) { if (x % a[i] == 0) returntrue; } returnfalse; }
ll phi(ll x) { ll ans = x; for (int i = 2; i * i <= x; i++) { if (x % i == 0) { ans = ans / i * (i - 1); // p^k * (p - 1) while (x % i == 0) x /= i; } } if (x > 1) ans = ans / x * (x - 1); return ans; } intmain() { // #define COMP_DATA #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif int Tcase; read(Tcase); for (int tcase = 1; tcase <= Tcase; tcase++) { read(n, m); for (int i = 1, x; i <= n; i++) { read(x); a[i] = __gcd(x, m); } n = unique(a + 1, a + 1 + n) - a - 1; ll ans = 0; for (int i = 1; i * i <= m; i++) { if (m % i == 0) { if (check(i)) { ans += phi(m / i); } if (i == 1 || i * i == m) continue; if (check(m / i)) { ans += phi(i); } } } ans = ans * m / 2; printf("Case #%d: %lld\n", tcase, ans); } return0; }