Problem Statement
The following game is called Game nn:
The game is played by Alice and Bob. Initially, there are nn stones.
The players alternate turns, making a move described below, with Alice going first. The player who becomes unable to make a move loses.
- In Alice's turn, she must remove a number of stones that is a positive multiple of AA.
- In Bob's turn, he must remove a number of stones that is a positive multiple of BB.
In how many of Game 11, Game 22, ..., Game NN does Alice win when both players play optimally?
Constraints
- 1 \leq N ,A,B \leq 10^{18}1≤N,A,B≤1018
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
NN AA BB
Output
Print the answer.
Sample 1
Inputcopy | Outputcopy |
---|---|
4 2 1 | 2 |
In Game 11, Alice cannot make a move and thus loses.
In Game 22, Alice removes 22 stones, and then Bob cannot make a move: Alice wins.
In Game 33, Alice removes 22 stones, Bob removes 11 stone, and then Alice cannot make a move and loses.
In Game 44, Alice removes 2 \times 2 = 42×2=4 stones, and then Bob cannot make a move: Alice wins.
Therefore, Alice wins in two of the four games.
Sample 2
Inputcopy | Outputcopy |
---|---|
27182818284 59045 23356 | 10752495144 |
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define mm(a) memset(a, 0, sizeof(a))
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
const int MOD = 998244353;
typedef long long ll;
const ll MAX = 1e18 + 5;
const ll MIN = 1e9 + 5;
const int N = 2e5 + 5;
ll n, a, b;
int main() {
// freopen("concatenation.in", "r", stdin);
// freopen("concatenation.out", "w", stdout);
cin >> n >> a >> b;
ll t, k;
ll sum = 0;
if (n < a)
{
printf("%lld\n", sum);
return 0;
}
if (a <= b) {
sum = n-a+1;
}
else
{
t = n / a;
k = n % a;
if (k >= b)
{
sum += t * b;
}
else sum += (t-1) * b + k + 1;
}
cout << sum << endl;
return 0;
}