This page is still under construction.

Parts of this page are still being built. What you see may change.

Next Number

Interview

Time limit1sMemory limit128 MB

Summary
Given three distinct integers from an arithmetic or geometric progression, decide which type it is and print the label with the next term.
Level

Easy2 of 10

Topics
Math, Implementation, Brute force, Number theory
Solved
No attempts yet

Problem

An arithmetic progression (AP) is a sequence in which the difference between two adjacent terms (the common difference) is constant. For example, 3, 5, 7, 9, 11, 13, … is an arithmetic progression whose common difference is a constant 2. In this problem the common difference is always a nonzero integer.

A geometric progression (GP) is a sequence in which the ratio between two adjacent terms (the common ratio) is constant. For example, 2, 6, 18, 54, … is a geometric progression with a common ratio of 3. In this problem the common ratio is always a nonzero integer.

Given three consecutive terms of a sequence, determine whether the sequence is an arithmetic progression or a geometric progression, then compute its next term.

Input

The input consists of several test cases. Each test case is a single line containing three consecutive integers of the sequence, a1a_1, a2a_2, a3a_3 (−10000<a1,a2,a3<10000-10000 < a_1, a_2, a_3 < 10000). The three integers are all distinct.

The last line of the input contains three zeros and must not be processed.

Output

For each test case, print AP if the sequence is an arithmetic progression or GP if it is a geometric progression, followed by the next term. Every input is always either an arithmetic or a geometric progression.

Examples3

  1. Example 1

    Input
    4 7 10
    2 6 18
    0 0 0
    
    Expected output
    AP 13
    GP 54
    
  2. Example 2

    Input
    3 6 12
    0 0 0
    
    Expected output
    GP 24
    
  3. Example 3

    Input
    10 7 4
    0 0 0
    
    Expected output
    AP 1