-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add problem from URI #math #combinatoric
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} |