Codeforces Testing Round #8 / 328A IQ Test(模拟)

A. IQ Test
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 a1a1 + da1 + 2d...a1 + (n - 1)d, where a1 and d are any numbers.

Geometric progression is a sequence b1b2 = b1q...bn = bn - 1q, where b1 ≠ 0q ≠ 0q ≠ 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.

Input

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

Output

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.

Sample test(s)
input
836 624 412 200
output
-12
input
1 334 667 1000
output
1333

water.


/*30ms,0KB*/

#include<cstdio>

int main()
{
	int a[4];
	for (int i = 0; i < 4; ++i)
		scanf("%d", &a[i]);
	if (a[0] + a[2] == (a[1] << 1) && a[1] + a[3] == (a[2] << 1))
		printf("%d", (a[3] << 1) - a[2]);
	else if (a[0]*a[2] == a[1]*a[1] && a[1]*a[3] == a[2]*a[2] && a[3]*a[3] % a[2] == 0)
        printf("%d", a[3] * a[3] / a[2]);
    else
        printf("42");
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值