Problem Statement

An adult game master and N children are playing a game on an ice rink. The game consists of K rounds. In the i-th round, the game master announces:

  • Form groups consisting of Ai children each!

Then the children who are still in the game form as many groups of Ai children as possible. One child may belong to at most one group. Those who are left without a group leave the game. The others proceed to the next round. Note that it's possible that nobody leaves the game in some round.

In the end, after the K-th round, there are exactly two children left, and they are declared the winners.

You have heard the values of A1A2, ..., AK. You don't know N, but you want to estimate it.

Find the smallest and the largest possible number of children in the game before the start, or determine that no valid values of N exist.

Constraints

  • 1≤K≤105
  • 2≤Ai≤109
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

K
A1 A2 AK

Output

Print two integers representing the smallest and the largest possible value of N, respectively, or a single integer −1 if the described situation is impossible.

Sample Input

4
3 4 3 2

Sample Output

6 8

怎么说呢,这题在愚人节出真的是耐人寻味,赤裸裸的模拟题啊。
显然,因为给定了结束时的人数,我们可以通过倒推求解。
对于min值,若上轮的每组人数正好可以整除当前人数,不做任何操作;否则,更新为当前人数和上轮每组人数的最小公倍数。
对于max值,记k为当前人数除以上轮每组人数向下取整,则更新为(k+1)*上轮每组人数-1。
对于无解情况,可以证明此时max小于min。
上代码!
#include<cstdio>
#include<cstring>
typedef long long ll;
int n;
ll a[],ans1=,ans2=;
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d",&a[i]);
for(int i=n;i;i--){
if(ans1%a[i])ans1/=a[i],ans1=ans1*a[i]+a[i];
ans2=(ans2/a[i]+)*a[i]-;
}
if(ans1>ans2)puts("-1");
else printf("%lld %lld\n",ans1,ans2);
return ;
}

[AtCoder3856]Ice Rink Game - 模拟的更多相关文章

  1. 【Atcoder】AGC 020 B - Ice Rink Game 递推

    [题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...

  2. AGC 020 B - Ice Rink Game

    题面在这里! 倒着维护可以取的范围区间,判一下可不可能无解即可. #include<bits/stdc++.h> #define ll long long using namespace ...

  3. AtCoder-3856

    An adult game master and N children are playing a game on an ice rink. The game consists of K rounds ...

  4. 【AtCoder】AGC020

    A - Move and Win 题解 看两个人相遇的时候谁先手即可,相遇之后第一个移动的人必输 代码 #include <bits/stdc++.h> #define fi first ...

  5. AtCoder Grand Contest 020

    A - Move and Win Time limit : 1sec / Memory limit : 512MB Score : 300 points Problem Statement A gam ...

  6. ICE CAVE(BFS搜索(模拟))

    Description You play a computer game. Your character stands on some level of a multilevel ice cave. ...

  7. CodeForces 686A Free Ice Cream (水题模拟)

    题意:给定初始数量的冰激凌,然后n个操作,如果是“+”,那么数量就会增加,如果是“-”,如果现有的数量大于等于要减的数量,那么就减掉,如果小于, 那么孩子就会离家.问你最后剩下多少冰激凌,和出走的孩子 ...

  8. 模拟--poj1835宇航员的故事

    这道题委实无语了,刚开始以为是很一般的方位模拟题,懒得看样例直接写的代码,然后敲了好几个switch结果样例居然没出来.. 仔细分析了样例之后才发现原来随着宇航员方位的改变他的左手方向以及头顶方向是跟 ...

  9. ICE学习——异步1

    ICE的AMI和AMD: AMI:指的是客户端的调用.一般有一个代理类,一个回调类. 从服务端返回的数据在回调类中的ice_response函数中. AMD:指的是服务端对客户端的调用分派.一般进行业 ...

随机推荐

  1. 搭建企业git代码版本管理所需工具

    此片文章纯属记录一下使用gitlab搭建私有git版本管理的一些工具及概念. 先记录一下概念 git         是一种版本控制系统,是一个命令,是一种工具 github   是一个基于git实现 ...

  2. Mac环境下Scrapy的安装

    直接命令安装: $ easy_install scrapy 从 GitHub 安装: $ git clonehttps://github.com/scrapy/scrapy.git $ cd scra ...

  3. R语言︱LDA主题模型——最优主题...

    R语言︱LDA主题模型——最优主题...:https://blog.csdn.net/sinat_26917383/article/details/51547298#comments

  4. Groovy Closure简介

    什么是闭包(Closure) 在Groovy中,闭包是一段匿名的代码段,它可以有参数,返回值,并且能够赋值给一个变量.闭包中使用的变量可以是在闭包外部定义的,也可以是在闭包内部定义的.

  5. Ajax 统一处理token失效

    complete:function ajax 请求完成激活本事件.这个方法很方便完成ajax 异常的处理. $.ajaxSetup({ contentType:"application/x- ...

  6. neutron--ml2 plugin

    ml2 plugin 对 plugin 的功能进行抽象和封装,有 ml2 plugin ,各种 network 无需开发自己的 plugin,只需开发 ml2 plugin 相对应的 driver , ...

  7. eclipse 的缓存问题

    写这篇文章 如果能带给你帮助 不胜荣幸 ,如果有问题和其他的见解 也欢迎批评指正.只要不进行人身攻击都好说. 今天的用eclipse(sts)写项目时候发生了很多缓存事情(也可能不是缓存).最后解决的 ...

  8. java中的static

    1.静态方法 在一个类中定义一个方法为static,那就是说,无需本类的对象即可调用此方法 声明为static的方法有以下几条限制: 1. 它们仅能调用其他的static 方法. 2· 它们只能访问s ...

  9. js中比较两个数组中是否含有相同的元素,可去重,可删除合并为新数组(转载)

    //做比较的两个数组 var array1 = ['a','b','c','d','e'];//数组1 var array2 = ['d','f','e','a','p'];//数组2 //临时数组存 ...

  10. pycharm的list中append的应用

    li = [11,22,33,44] li.append(5) print(li) #输出结果 [11,22,33,44,5] #后面可加字母,列表等字符串