The game is played by Alice and Bob. Initially, there are $n$ 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 $A$.
  • In Bob's turn, he must remove a number of stones that is a positive multiple of $B$.

In how many of Game $1$, Game $2$, ..., Game $N$ does Alice win when both players play optimally?

Constraints

  • $1 \leq N ,A,B \leq 10^{18}$
  • 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 $1$, Alice cannot make a move and thus loses.

In Game $2$, Alice removes $2$ stones, and then Bob cannot make a move: Alice wins.

In Game $3$, Alice removes $2$ stones, Bob removes $1$ stone, and then Alice cannot make a move and loses.

In Game $4$, Alice removes $2 \times 2 = 4$ 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

### 题解
设这一局有 $x$ 个石子,先手取完石子后有 $x'$ 个石子。同时先手取得石子是 $a$ 的倍数,后手取的石子为 $b$ 的倍数
1. 若 $xa$ 且 $a\le b$,先手可以取尽量多的石子,则 $x'=x \bmod a$ 个石子,因为 $x'=(x \bmod a)a$ 且 $a>b$,如果先手取完石子后,$x'\ge b$,那么轮到后手时变成情况 2。所以当且仅当 $x'综上所述,先手必胜的条件是 \((x\ge a)\) 且 \((x \bmod a<b)\)

所以问题转化为有多少个 \(x\in[A,n]\) 满足 \(x \bmod A<b\)

把 \([A,n]\) 的数按照 \(\bmod A\) 的余数分组,每 \(A\) 个为一组。那么共有 \(\left\lfloor\frac{n-A}{A}\right\rfloor\) 个完整的组。每一组里面有 \(\min(a,b)\) 个合法的数。剩下的 \(n \bmod A +1\) 个数里面又有 \(\min(n\bmod A+1,b)\) 个合法的数。我们就可以 \(O(1)\) 求出答案。

注意特判 \(n<A\)

#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;
}

[ARC145B] AB Game的更多相关文章

  1. ab

     ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed ...

  2. 使用ab对nginx进行压力测试

    nginx以高并发,省内存著称. 相信大多数安装nginx的同学都想知道自己的nginx性能如何. 我想跟大家分享下我使用ab工具的压力测试方法和结果, ab是针对apache的性能测试工具,可以只安 ...

  3. apache的AB测试

    A/B测试A/B测试是一种新兴的网页优化方法,可以用于增加转化率注册率等网页指标..A/B测试的目的在于通过科学的实验设计.采样样本代表性.流量分割与小流量测试等方式来获得具有代表性的实验结论,并确信 ...

  4. apache自带ab压测

    ./ab -k -n100000 -c100 http://localhost/index.php -k表示保持连接keep-alive -n表示请求数 -c表示并发数 (总结)Web性能压力测试工具 ...

  5. 压力测试相关之ab命令

    1. 短时压力测试工具 ab 命令(apache的工具) 关键指标: Requests per second:    98.52 [#/sec] (mean)      ###平均每秒的请求数 Tim ...

  6. 【转载】AB测试结果分析

    AB测试,200个请求,20个并发.这样的测试强度,CPU占了70-80%,w3p占用了70多M内存,本想多测几次,看看它的内存会不会涨上去,没 有测试机器没办法,开发机要干活.我估计CPU就有问题了 ...

  7. 使用Apache Server 的ab进行web请求压力测试

    参考:http://www.cnblogs.com/spring3mvc/archive/2010/11/23/2414741.html 自己写代码经常是顺着逻辑写下去,写完后run一下,ok就玩完事 ...

  8. apache ab测试命令详解

    这篇文章主要介绍了apache性能测试工具ab使用详解,需要的朋友可以参考下   网站性能压力测试是服务器网站性能调优过程中必不可缺少的一环.只有让服务器处在高压情况下,才能真正体现出软件.硬件等各种 ...

  9. 使用ab进行压力测试详解

    ab是apache自带的压力测试工具,非常好用.转载几篇对ab工具的详细使用的博文.猛击下面的链接地址 http://www.365mini.com/page/apache-benchmark.htm ...

  10. centos ab命令安装

    yum install apr-util -ymkdir abcd abyum -y install yum-utils -yyumdownloader httpd yum localinstall ...

随机推荐

  1. 移动优先与响应式Web设计

    1.加速度计-设备置向 2.下拉更新-Iscroll 3.滑动以得到更多选项-panel 4.Sketch a Search 雅虎 画圈搜索 5.<Tapeworthy> 移动用户的行为特 ...

  2. arthas的安装及使用

    arthas的安装及使用 官方文档 安装 #1.下载 https://arthas.aliyun.com/download/latest_version?mirror=aliyun #2.将下载文件上 ...

  3. Codeforces 1462E2 Close Tuples (hard version)

    题意 给一个长度为\(n\)的数组,取\(m\)个数字,其中最大值最小值相差不大于\(k\),问这种方式有多少种,答案\(\mod 10^9+7\). 分析 通过简单版本大概了解了这题要枚举最小值来判 ...

  4. burpsuite验证码爆破后台夺权

    目录 准备工作 爆破 同时爆破用户名密码和验证码 筛查爆破结果的成功输出 创建新用户远程桌面连接 准备工作 安装python 安装muggle_ocr库 运行xp_CAPTCHA服务端 burpsui ...

  5. vue中watch侦听器,deep和immediate的用法

    1.deep深度监听的用法 当监听一个对象时,可能想监听整个对象的变化,而不仅仅是某个属性.但在默认情况下,如果你正在监听formData对象并且修改了formData.username,对应的侦听器 ...

  6. Mybatis中的设计模式

    最近在看<通用源码阅读指导书:Mybatis源码详解>,这本书一一介绍了Mybatis中的各个包的功能,同时也涉及讲了一些阅读源码的技巧,还讲了一些源码中涉及的设计模式,这是本篇文章介绍的 ...

  7. 洛谷题解 | AT_abc321_c Primes on Interval

    目录 题目翻译 题目描述 输入格式 输出格式 样例 #1 样例输入 #1 样例输出 #1 样例 #2 样例输入 #2 样例输出 #2 样例 #3 样例输入 #3 样例输出 #3 题目简化 题目思路 A ...

  8. oj练习题 数字 eval 整数 int ???

    s = input()if 'hello world!' == s.casefold(): print("Yes")else: print("No") A+B问 ...

  9. 将GitBash设置为VS Code的默认终端

    这个东西搞了半天,真的无语...网上的东西都太旧了 注意:"terminal.integrated.shell.windows"自2021年4月起已弃用. 1.首先打开设置 2.进 ...

  10. Chrome Extensions v3 迁移清单

    一.前置问题 1.1为什么需要迁移 v3? Chrome 计划完全停止 v2 版本维护,后续 v2 版本将无法上架谷歌插件商店,除此之外,未来新版本 Chrome 对于 v2 版本插件的限制会越来越大 ...