fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve() {
  5. int n;
  6. long long k;
  7. cin >> n >> k;
  8. vector<long long> a(n);
  9. for (int i = 0; i < n; i++) cin >> a[i];
  10.  
  11. long long lim = k*k;
  12. auto lcm = [lim](long long x, long long y) {
  13. __int128 z = (__int128)x/gcd(x, y)*y;
  14. return z > lim ? lim+1 : (long long)z;
  15. };
  16. auto round = [&]() {
  17. vector<long long> pre(n+1, 1), suf(n+1, 1);
  18. for (int i = 0; i < n; i++) {
  19. pre[i] = lcm(pre[i-1], a[i]);
  20. suf[n-i-1] = lcm(suf[n-i], a[n-i-1]);
  21. if (pre[i] > lim) return 0;
  22. if (suf[n-i-1] > lim) return 0;
  23. }
  24. for (int i = 0; i < n; i++) {
  25. if (a[i] == 1) continue;
  26. long long ll = lcm(pre[i-1], suf[i+1]);
  27. if ((ll <= k) && (gcd(ll, a[i]) == 1)) {
  28. a[i] = 1;
  29. return 1;
  30. }
  31. }
  32. return 0;
  33. };
  34.  
  35. for (int i = 0; i <= n; i++) {
  36. if (round()) continue;
  37. cout << (i&1 ? "Alice" : "Bob") << '\n';
  38. break;
  39. }
  40. }
  41.  
  42. int main() {
  43. int t;
  44. cin >> t;
  45. while (t--) solve();
  46. }
  47.  
Success #stdin #stdout 0s 544KB
stdin
Standard input is empty
stdout
Standard output is empty