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