ACPC10A - What’s Next

no tags 

According to Wikipedia, 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 instance, the sequence 3, 5, 7, 9, 11, 13 ... is an arithmetic progression with common difference 2. For this problem, we will limit ourselves to arithmetic progression whose common difference is a non-zero integer.

On the other hand, 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 number called the common ratio. For example, the sequence 2, 6, 18, 54 ... is a geometric progression with common ratio 3. For this problem, we will limit ourselves to geometric progression whose common ratio is a non-zero integer.

Given three successive members of a sequence, you need to determine the type of the progression and the next successive member.

Input

Your program will be tested on one or more test cases. Each case is specified on a single line with three integers (−10, 000 < a1, a2, a3 < 10, 000) where a1, a2, and a3 are distinct.

The last case is followed by a line with three zeros.

Output

For each test case, you 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.

Example

Input:
4 7 10
2 6 18
0 0 0

Output:
AP 13
GP 54

hide comments
nixeagle: 2011-11-10 20:39:03

I just got AC using Haskell. However there is some misinformation in these comments I'd like to clear up for those that follow.

@SARIH Mohamed - Please note the problem *specifically* excludes floating points. Additionally note that the range the problem covers easily fits in a machine word (read: C/C++ int).

@Jayanth Koushik - Note the problem specifically states that a1 != a2 != a3.

Ivan Sto¹iæ: 2011-08-22 12:58:55

i changed from int to long and got AC
also, i changed %d to %ld

blashyrkh: 2011-07-26 13:29:23

Accepted without floats. All inputs are distinct integers, so it's not possible that both AP and GP. %d is correct format specifier for printf.

SARIH Mohamed: 2011-07-25 09:44:58

Accepted with some keys for c++ users:
-usage of floats;
-usage of printf with %g;
-priority to AP for an AP and GP series in case of AP and GP on the same time

for input "1 1 1" output must be "AP 1"
for input "125 62.5 31.25" output must be "GP 15.625"
for input "6 2 9" no output

Last edit: 2011-07-25 09:52:21
ujjwal kumar upadhyay: 2011-06-25 16:19:05

getting WA. i hv checked every possible test case.same happened with ADDREV to me.it showed WA for 3-4 times but with the same code ,it got accepted!! maybe ther's some fault with this site's compiler!!(or is it bcs of my slow et speed)

Atanu: 2011-06-08 09:25:26

I got WA for no reason ...it so simple problem...any special cases??????

SD: 2011-06-03 07:14:21

:P

Last edit: 2011-06-03 08:52:22
Rocker3011: 2011-04-22 07:57:52

-.- i made 100 test cases all good, i put it on... WA why?

LeBron: 2011-03-31 17:42:14

Jordan Spell, there are no such cases.
My solution got AC with integer type.

tboyd: 2011-03-31 17:42:14

grownup, a1,a2 and a3 are distinct.


Added by:Omar ElAzazy
Date:2010-11-30
Time limit:1.799s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:ACPC 2010