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 1

4
3 4 3 2

Sample Output 1

6 8

For example, if the game starts with 6 children, then it proceeds as follows:

  • In the first round, 6 children form 2 groups of 3 children, and nobody leaves the game.
  • In the second round, 6 children form 1 group of 4 children, and 2 children leave the game.
  • In the third round, 4 children form 1 group of 3 children, and 1 child leaves the game.
  • In the fourth round, 3 children form 1 group of 2 children, and 1 child leaves the game.

The last 2 children are declared the winners.

Sample Input 2

5
3 4 100 3 2

Sample Output 2

-1

This situation is impossible. In particular, if the game starts with less than 100children, everyone leaves after the third round.

Sample Input 3

10
2 2 2 2 2 2 2 2 2 2

Sample Output 3

2 3

题解:这道题应该倒过来反推;代码如下:

AC代码为:

#include <iostream>  
#include <cstdio>  
using namespace std;

int a[100005];
int main() 
{
int k;
cin >> k;
for (int i = 1; i <= k; i++) 
{
cin >> a[i];
}
long long mmax = 2, mmin = 2;
for (int i = k; i >= 1 && mmax >= mmin; i--)
{
if (mmin%a[i] != 0)
mmin = mmin / a[i] * a[i] + a[i];
mmax = (mmax / a[i] + 1)*a[i] - 1;
}
if (mmax >= mmin)
cout << mmin << ' ' << mmax << endl;
else
cout << -1 << endl;

return 0;
}

AtCoder-3856的更多相关文章

  1. AtCoder Regular Contest 061

    AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...

  2. 【BZOJ】【3856】Monster

    又是一道水题…… 重点是分情况讨论: 首先我们很容易想到,如果a*k-b*(k+1)>0的话那么一定能磨死Monster. 但即使不满足这个条件,还有可能打死boss: 1.h-a<1也就 ...

  3. AtCoder Grand Contest 001 C Shorten Diameter 树的直径知识

    链接:http://agc001.contest.atcoder.jp/tasks/agc001_c 题解(官方): We use the following well-known fact abou ...

  4. 3856: Monster

    3856: Monster Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 351  Solved: 161[Submit][Status][Discuss ...

  5. AtCoder Regular Contest 082

    我都出了F了……结果并没有出E……atcoder让我差4分上橙是啥意思啊…… C - Together 题意:把每个数加1或减1或不变求最大众数. #include<cstdio> #in ...

  6. AtCoder Regular Contest 069 D

    D - Menagerie Time limit : 2sec / Memory limit : 256MB Score : 500 points Problem Statement Snuke, w ...

  7. AtCoder Regular Contest 076

    在湖蓝跟衡水大佬们打的第二场atcoder,不知不觉一星期都过去了. 任意门 C - Reconciled? 题意:n只猫,m只狗排队,猫与猫之间,狗与狗之间是不同的,同种动物不能相邻排,问有多少种方 ...

  8. AtCoder Grand Contest 016

    在雅礼和衡水的dalao们打了一场atcoder 然而窝好菜啊…… A - Shrinking 题意:定义一次操作为将长度为n的字符串变成长度n-1的字符串,且变化后第i个字母为变化前第i 或 i+1 ...

  9. AtCoder Beginner Contest 069【A,水,B,水,C,数学,D,暴力】

    A - K-City Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement In K-city, ...

  10. AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle

    https://beta.atcoder.jp/contests/abc075/tasks/abc075_d 题意: 给出坐标平面上n个点的坐标,要求找到一个面积最小的矩形使得这个矩形的边界加上内部的 ...

随机推荐

  1. 模拟实现IoC容器

    Spring的IoC核心就是控制反转,将对实现对象的操作控制器交出来,由IoC容器来管理,从配置文件中获取配置信息,Java对XML文档提供了完美的支持,dom4j功能强大,而下面我就用JDOM这一开 ...

  2. Ansible之playbook拓展

    一.handlers和notify结合使用触发条件 handlers同tasks是属同级,相当于一个特殊任务列表,这些任务同前文说的tasks里的任务没有本质的不同,用于当关注的资源发生变化时,才会采 ...

  3. [springboot 开发单体web shop] 6. 商品分类和轮播广告展示

    商品分类&轮播广告 因最近又被困在了OSGI技术POC,更新进度有点慢,希望大家不要怪罪哦. 上节 我们实现了登录之后前端的展示,如: 接着,我们来实现左侧分类栏目的功能. ## 商品分类|P ...

  4. 简单地迁移你的android jni代码逻辑到iOS - 编写iOS下jni.h的替代 - ocni.h

    1. jni的代码逻辑中与上层平台语言交互了. 2. 使用非Xcode的ide开发工具,希望使用纯净的c/c++代码,不掺杂其它平台相关的语言语法. 3. 只想简单地替换jni代码对上层平台语言的功能 ...

  5. 使用ASP.NET Core 3.x 构建 RESTful API - 3.2 路由和HTTP方法

    ASP.NET Core 3.x 的路由 路由机制会把一个请求的URI映射到一个Controller上面的Action,所以当你发送一个HTTP请求的时候,MVC框架会解析这个请求的URI,并尝试着把 ...

  6. 在Raspberry Pi上创建容器

    树莓派Raspbian默认是支持LXC容器的,下面我们介绍一下在树莓派上创建并运行容器的过程. 1. 安装LXC相关的package $ sudo apt-get install -y git lxc ...

  7. Flex调用本地文件分析

    最近在用Flex做一个相册的功能,因为图片数据很多,所以想调用本地文件的方式做. 但是B/S的缘故,很多安全上的限制给我造成了不小的麻烦,把我这个小菜鸟弄的晕头转向. 第一,刚开始,查了很多资料发现都 ...

  8. 防范XSS攻击

    原文链接:http://www.cnblogs.com/chenty/p/5136834.html 最近,有个项目突然接到总部的安全漏洞报告,查看后知道是XSS攻击. 问题描述: 在页面上有个隐藏域: ...

  9. 使用three.js创建大小不随着场景变化的文字

    使用three.js创建大小不随着场景变化的文字,需要以下两步: 1.将文字绘制到画布上. 2.创建着色器材质,把文字放到三维场景中. 优点: 1.跟用html实现文字相比,这些文字可以被模型遮挡,更 ...

  10. Bash Shell编程简记

    Shell编程简记 经常在linux环境下开发的同学,难免要使用shell的一些命令或者编写小的脚本,我这里也总结和整理下,自己对Shell的理解和常用的一些shell脚本. 按照目录分为如下3个节: ...