[ARC145B] AB Game
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的更多相关文章
- ab
ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed ...
- 使用ab对nginx进行压力测试
nginx以高并发,省内存著称. 相信大多数安装nginx的同学都想知道自己的nginx性能如何. 我想跟大家分享下我使用ab工具的压力测试方法和结果, ab是针对apache的性能测试工具,可以只安 ...
- apache的AB测试
A/B测试A/B测试是一种新兴的网页优化方法,可以用于增加转化率注册率等网页指标..A/B测试的目的在于通过科学的实验设计.采样样本代表性.流量分割与小流量测试等方式来获得具有代表性的实验结论,并确信 ...
- apache自带ab压测
./ab -k -n100000 -c100 http://localhost/index.php -k表示保持连接keep-alive -n表示请求数 -c表示并发数 (总结)Web性能压力测试工具 ...
- 压力测试相关之ab命令
1. 短时压力测试工具 ab 命令(apache的工具) 关键指标: Requests per second: 98.52 [#/sec] (mean) ###平均每秒的请求数 Tim ...
- 【转载】AB测试结果分析
AB测试,200个请求,20个并发.这样的测试强度,CPU占了70-80%,w3p占用了70多M内存,本想多测几次,看看它的内存会不会涨上去,没 有测试机器没办法,开发机要干活.我估计CPU就有问题了 ...
- 使用Apache Server 的ab进行web请求压力测试
参考:http://www.cnblogs.com/spring3mvc/archive/2010/11/23/2414741.html 自己写代码经常是顺着逻辑写下去,写完后run一下,ok就玩完事 ...
- apache ab测试命令详解
这篇文章主要介绍了apache性能测试工具ab使用详解,需要的朋友可以参考下 网站性能压力测试是服务器网站性能调优过程中必不可缺少的一环.只有让服务器处在高压情况下,才能真正体现出软件.硬件等各种 ...
- 使用ab进行压力测试详解
ab是apache自带的压力测试工具,非常好用.转载几篇对ab工具的详细使用的博文.猛击下面的链接地址 http://www.365mini.com/page/apache-benchmark.htm ...
- centos ab命令安装
yum install apr-util -ymkdir abcd abyum -y install yum-utils -yyumdownloader httpd yum localinstall ...
随机推荐
- Linux下后台运行Java程序
1.背景描述 用Java编写了一个程序(可执行的jar),需要在Linux中启动并持续运行 1.1.直接执行程序 直接执行程序后,在程序执行期间,无法在当前会话中再执行其他操作 1.2.直接执行程序后 ...
- 开源Word文字替换小工具更新 增加文档页眉和页脚替换功能
ITGeeker技术奇客发布的开源Word文字替换小工具更新到v1.0.1.0版本啦,现已支持Office Word文档页眉和页脚的替换. 同时ITGeeker技术奇客修复了v1.0.0.0版本因替换 ...
- DeferredResult异步处理spring mvc Demo
一.概述 spring mvc同步接口在请求处理过程中一直处于阻塞状态,而异步接口可以启用后台线程去处理耗时任务.简单来说适用场景: 1.高并发: 2.高IO耗时操作. 二.Demo Spring M ...
- js调起android安卓与ios苹果方法 vue3.0 + ts
let shareSelect = (ev :any) => { const u :any= navigator.userAgent; const win :any = window const ...
- DEDEBIZ禁止发布重复标题文章的方法
修改文件位置 /admin/article_add.php 找到 if (empty($click)) $click = ($cfg_arc_click == '-1' ? mt_rand(1000, ...
- 堆的原理以及实现O(lgn)
大家好,我是蓝胖子,我一直相信编程是一门实践性的技术,其中算法也不例外,初学者可能往往对它可望而不可及,觉得很难,学了又忘,忘其实是由于没有真正搞懂算法的应用场景,所以我准备出一个系列,囊括我们在日常 ...
- PLSQL_developer安装与配置
前言: 记录安装与配置操作 环境: 客户机:windows 服务器:虚拟机中的windows server 2003 /---------------------------------------- ...
- Factors 分解质因数
package com.yourself.yours; import java.util.Scanner; /** ****************************************** ...
- CentOS yum配置
一.yum 安装 CentOS 默认已经安装了yum,不需要另外安装,这里为了实验目的,先将yum 卸载再重新安装. 1.查看系统默认安装的yum # rpm -qa|grep yum 2.卸载yum ...
- 记一次MySQL5初始化被kill的问题排查
写在前面 由于测试环境JED申请比较繁琐,所以Eone提供了单机版Mysql供用户使用,近期Eone搭建Mysql5的时候发现莫名被kill了,容器规格是4C8G,磁盘30G 这不科学,之前都是可以的 ...