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. vue 脚手架文件结构及加载过程浅谈

    1. 初始化脚手架 1.1  全局安装 @vue/cli  npm install -g @vue/cli 1.2 切换到创建项目的目录,执行 vue create projectname 1.3 选 ...

  2. ffmpeg 在xp和server2003/2008/2012上修复无法定位GetNumaNodeProcessorMaskEx的问题

    问题 在给开发一个手机视频网站时需要用到ffmpeg截取视频缩略图, 把项目提交到服务器(server2003/ server2008)上时, 发现在调用命令时会出现错误"无法定位GetNu ...

  3. ps aux 命令使用

    转载请注明出处: ps aux​​命令是一个常用的Linux/Unix系统命令,它用于查看正在运行的进程信息.下面是该命令使用的参数介绍.命令响应结果参数介绍以及一些使用实例的总结: 命令使用参数介绍 ...

  4. Building-Mobile-Apps-with-Ionic-2中文翻译工作

    最近没啥工作量, 然后学完了这本书, 接着又茫然找不到该干啥, 所以想着何不翻译这个书呢. 这本书首先给我们普及了Ionic 2的基础知识, Ionic 2和Ionic 1有本质上的区别, Ionic ...

  5. 「にちじょう記録」MTIDnWtMOA

    Mistakes That I Don't Want to Make Once Again. // Caution // 差分 / 前缀和后注意询问区间端点有变化-- 不要考虑了右边界就不考虑左边界 ...

  6. oracle-应用连接数激增测试

    在生产环境遇见过表的连接数过高,导致系统宕机的问题,操作上是由于在大表上建立索引,造成全表锁.故手动在表加表级锁,表上的应用不停,查看Oracle数据库连接数是否激增. 1 应用正常运行,查看当前数据 ...

  7. 如何用CAN-EYE获取植被参数数据?

      本文介绍植被冠层参数计算软件CAN-EYE的具体使用方法.   在文章下载.安装CAN-EYE植被参数工具中,我们介绍了CAN-EYE软件的下载.安装方法:本文就对该软件的具体使用方法进行介绍. ...

  8. ACL 与NAT

    ACL 概述 acl是由一系列permit或deny语句组成.有序规则的列表. ACL是一个匹配工具,能够对报文进行匹配和区分. 应用 匹配流量 在traffic-filter中备调用 在NAT中被调 ...

  9. 一键修改IP多实例

    一键修改IP多实例-v1 #!/bin/bash #2020-03-01 #auto change ip #By Flyaway ###################### grep "d ...

  10. unity2017自定义编译dll

    适用于自定义编译平台和编译符合,把C#源码文件编译成dll.(用于InjectFix之类的热更方案) 适用于unity2017环境,代码暂时不方便贴出记述一下思路. 参考:Unity官方C#源码 ht ...