A9144 | IQ Test
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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}+2d$ , $...$ , $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.
Arithmetic progression is a sequence $a_{1}$ , $a_{1}+d$ , $a_{1}+2d$ , $...$ , $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.
输入格式
The first line contains exactly four integer numbers between 1 and 1000, inclusively.
输出格式
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.
Print 42 if the given sequence is not an arithmetic or geometric progression.
输入输出样例
输入 #1
836 624 412 200
输出 #1
-12
输入 #2
1 334 667 1000
输出 #2
1333
This problem contains very weak pretests!
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted