CF328A.IQ Test

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions.

Arithmetic progression is a sequence _a_1, _a_1 + d, a_1 + 2_d, ..., _a_1 + (n - 1)d, where _a_1 and d are any numbers.

Geometric progression is a sequence _b_1, b_2 = b_1_q, ..., b__n = b__n - 1_q, where _b_1 ≠ 0, q ≠ 0, q ≠ 1.

Help Petya and write a program to determine if the given sequence is arithmetic or geometric. Also it should found the next number. If the sequence is neither arithmetic nor geometric, print 42 (he thinks it is impossible to find better answer). You should also print 42 if the next element of progression is not integer. So answer is always integer.

佩佳正在为智商测试做准备,他注意到有很多这类题目:给你一个数列,求它的下一个数字。目前佩佳只能解决等差数列或等比数列的问题。

等差数列是一个形如 a1, a1+d, a1+2d, …, a1+(n−1)da_1,\ a_1 + d,\ a_1 + 2d,\ \dots,\ a_1 + (n - 1)d 的序列,其中 a1a_1 和 dd 可以是任意实数。

等比数列是一个形如 b1, b2=b1q, …, bn=bn−1qb_1,\ b_2 = b_1 q,\ \dots,\ b_n = b_{n-1} q 的序列,其中 b1≠0b_1 \neq 0,q≠0q \neq 0,且 q≠1q \neq 1。

请帮助佩佳编写一个程序,判断给定的数列是等差数列还是等比数列,并求出它的下一个数字。如果该数列既不是等差数列也不是等比数列,则输出 42(他认为这是无法找到更好答案的情况)。此外,如果该数列所对应的等差或等比数列的下一个元素不是整数,也应输出 42。因此,最终答案始终为整数。

输入格式

The first line contains exactly four integer numbers between 1 and 1000, inclusively.

第一行恰好包含四个介于 1 到 1000(含)之间的整数。

输出格式

Print the required number. If the given sequence is arithmetic progression, print the next progression element. Similarly, if the given sequence is geometric progression, print the next progression element.

Print 42 if the given sequence is not an arithmetic or geometric progression.

输出所需的数字。如果给定序列是等差数列,则输出该等差数列的下一个项;如果给定序列是等比数列,则输出该等比数列的下一个项。

如果给定序列既不是等差数列也不是等比数列,则输出 42。

输入输出样例

  • 输入#1

    836 624 412 200

    输出#1

    -12
  • 输入#2

    1 334 667 1000

    输出#2

    1333

说明/提示

This problem contains very weak pretests!

本题的预测试非常弱!

输入解题思路,AI测评打分。不知道怎么写?

首页