Problem description. An arithmetic progression(AP) is a sequence of numbers such that…
- User
Problem description. An arithmetic progression(AP) is a sequence of numbers such that the difference of any two successive members of the sequence is a constant. For example:- 1, 4, 7, 10, 13, 16, 19, ... A geometric progression(GP) is a sequence of numbers where each term after the first is found by multiplying the previous one by a fixed non-zero contant. For examplee:- 1, 3, 9, 81, ... (with common ratio of 3). Given three successive members of a sequence, you need to determine the type of the progression and the next successive member. Input
Each case is specified on a single line with three integers a1, a2, a3 are distinct. The last case is followed by a line with three zeros.
Output
For each test case, your program must print a single line of the form: XX v where XX is either AP or GP depending if the given progression is an Arithmetic or Geometric Progression. v is the next member of the given sequence. All input cases are guaranteed to be either an arithmetic or geometric progressions.
Constraints
Example Input: 4 7 10 2 6 18 0 0 0 Output: AP 13 GP 54
Assistant
pythonimport sys for line in sys.stdin: a1, a2, a3 = map(int, line.strip().split()) if a1 == 0 and a2 == 0 and a3 == 0: break if a2 - a1 == a3 - a2: next_term = a3 + (a2 - a1) print(f"AP {next_term}") else: next_term = (a3 * a3) // a2 print(f"GP {next_term}")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.