[ARC145B] AB Game
The game is played by Alice and Bob. Initially, there are 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 .
- In Bob's turn, he must remove a number of stones that is a positive multiple of .
In how many of Game , Game , ..., Game does Alice win when both players play optimally?
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
$N$ $A$ $B$
Output
Print the answer.
Sample Input 1
4 2 1
Sample Output 1
2
In Game , Alice cannot make a move and thus loses.
In Game , Alice removes stones, and then Bob cannot make a move: Alice wins.
In Game , Alice removes stones, Bob removes stone, and then Alice cannot make a move and loses.
In Game , Alice removes stones, and then Bob cannot make a move: Alice wins.
Therefore, Alice wins in two of the four games.
Sample Input 2
27182818284 59045 23356
Sample Output 2
10752495144
所以问题转化为有多少个 满足
把 的数按照 的余数分组,每 个为一组。那么共有 个完整的组。每一组里面有 个合法的数。剩下的 个数里面又有 个合法的数。我们就可以 求出答案。
注意特判
#include<bits/stdc++.h>
#define ll long long
#define p1 998244353
#define p2 1000000007
using namespace std;
ll n,a,b,ans;
int main()
{
scanf("%lld%lld%lld",&n,&a,&b);
if(n<a) printf("0");
else{
n-=a;
ans+=n/a*min(a,b);
n-=n/a*a;
printf("%lld\n",ans+min(n+1,b));
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】