IQ Test
Time limit2sMemory limit128 MB
Given an integer sequence, decide whether an integer rule next = a*prev + b determines the next term uniquely, ambiguously, or not at all.
- Level
Medium5 of 10
- Topics
- Math, Implementation, Simulation
- Solved
- No attempts yet
Problem
You are given an integer sequence. Determine the next value under a rule of the form next term = previous term * a + b, where both a and b are integers.
If the next value is uniquely determined, print that value. If several next values are possible, print A. If no integer pair a, b can generate the given sequence, print B.
Input
The first line contains N, a positive integer not greater than 50. The second line contains N integers separated by spaces. The absolute value of each integer is at most 100.
Output
Print the next value. If several next values are possible, print A. If the next value cannot be determined because the sequence cannot be generated by any valid rule, print B.