**Hey thanks for the reply! . I modified the code to handle APs starting with 0.Now it works fine for such inputs on ideone but still shows NZEC error when i submit. I dont get why it shows NZEC error? **
import java.util.*;
import java.math.BigInteger;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(true)
{
int a =sc.nextInt();
int b =sc.nextInt();
int c =sc.nextInt();
if((a==0)&&(b==0)&&(c==0)) break;
int d1=b-a;
int d2=c/b;
if((b==a+d1)&&(c==a+2*d1))
{
System.out.println("AP"+" "+ (a+3*d1));
}
if((b/d2==a)&&(c/d2==b)&&a!=0)
{
BigInteger b1 = new BigInteger(String.valueOf(d2));
BigInteger b2 = new BigInteger(String.valueOf(a));
System.out.println("GP"+" "+ b2.multiply(b1.pow(3)));
}
}
}
}