Repository navigation
Expand file tree
/
Copy path1904.cpp
More file actions
69 lines (53 loc) · 1.33 KB
/
Copy path1904.cpp
File metadata and controls
69 lines (53 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// https://www.urionlinejudge.com.br/judge/en/problems/view/1904
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;
const int mx = 1e7 + 10;
long long fact[mx];
vector<long long> primes;
long long cnt_primes[mx];
vector<long long> criba(mx, true);
// test parity for C(n, k)
bool calc (long long n, long long k) {
return (k & (n - k)) ? 0 : 1;
}
long long count_primes (long long a, long long b) {
return cnt_primes[b] - cnt_primes[a - 1];
}
void gen_primes () {
for (int i = 2; i < mx; ++i) {
if (criba[i]) {
int j = 2;
while (i * j < mx) {
criba[i * j] = false;
j ++;
}
}
}
criba[0] = criba[1] = 0;
}
int main() {
gen_primes();
long long a, b;
for (int i = 1; i < mx; ++i) {
criba[i] += criba[i - 1];
}
while (cin >> a >> b) {
if (a > b) swap(a, b);
if (a == b) {
cout << "?" << endl;
continue;
}
long long n = b - a;
long long r = criba[b] - criba[max(0LL, a - 1)];
// |n+r-1| (n+r-1)! |n+r-1| n!
// | | = ---------- = | | = ----------
// | r | r! * (n-1)! | n | r! * (n-r)!
//
// from stars and bars Theorem
bool ans = calc(n + r - 1, n);
cout << (ans ? "Alice" : "Bob") << endl;
}
return 0;
}