import java.util.*;
import java.math.BigInteger;
class Solution
{
        public static void main(String arr[])
        {
                Scanner p=new Scanner(System.in);
                int t=p.nextInt();
                int im=1;
                while(t>=1)
                {
                BigInteger n=new BigInteger(p.next());
                int l=p.nextInt();
                ArrayList<BigInteger> val=new ArrayList<BigInteger>();
                int i,j;
                ArrayList<BigInteger> pval=new ArrayList<BigInteger>();
                for(i=0;i<l;i++)
                        val.add(new BigInteger(p.next()));
                int h=0,rajesh=0;
                BigInteger x,y,xx,yy;
                BigInteger two=new BigInteger("2");
                BigInteger one=new BigInteger("1");
                BigInteger zero=new BigInteger("0");
                BigInteger three=new BigInteger("3");
                BigInteger temp=new BigInteger("0");
                BigInteger temp2=new BigInteger("0");
                BigInteger b1=new BigInteger("0");
                BigInteger b2=new BigInteger("0");
                yy=val.get(0);
                BigInteger ono=new BigInteger("101");
        if(n.compareTo(ono)==0)
        {
                pval.add(one);
                pval.add(yy);
                b1=yy;
                b2=one;
                h++;
        }
                else
                {
                for(x=three;x.compareTo(yy)==-1;x=x.add(one))
                {
                
                        for(y=two;y.compareTo(x)==-1;y=y.add(one))
                        {
                                temp=x.mod(y);
                                
                                
                                if(temp.compareTo(zero)==0)
                                break;
                        }
                        
                
                                if(x.compareTo(y)==0)
                                {
                                        
                                        temp=yy.divide(x);
                                        temp2=yy.mod(x);
                                        
                                        
                                        if(temp2.compareTo(zero)==0)
                                        {
                                                b1=x;
                                                
                                                b2=temp;
                                                pval.add(b1);
                                                pval.add(b2);
                                                rajesh=1;
                                                h++;
                                                break;
                                        }
                                }
                }
                        
        
                }
                
                if(h<l)
                {
                temp=val.get(h).divide(b1);
                        temp2=temp.multiply(b1);
                if(temp2.compareTo(val.get(h))==0)
                        i=0;
                else
                        temp=val.get(h).divide(b2);
                pval.add(temp);
                }
                
                for(i=2;i<l;i++)
                {
                        temp2=val.get(i).divide(temp);
                        if(!pval.contains(temp2))
                        pval.add(temp2);
                        temp=temp2;
                        
                }
        
                Collections.sort(pval);

                String str="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
StringBuilder strb=new StringBuilder();
char ch[]=str.toCharArray();
h=0;
        
        for(i=0;i<pval.size();i++)
        {
                for(j=0;j<pval.size();j++)
                {
                        temp=pval.get(i).multiply(pval.get(j));
                        if(temp.compareTo(val.get(h))==0)
                        {
                                strb.append(ch[i]);
                                strb.append(ch[j]);
                                temp=pval.get(j);
                                
                                h++;
                                break;
                        }
                }
                if(h>0)
                        break;
        }
        
        if(h<l)
        {
                
        for(i=0;;i++)
        {
                temp2=temp.multiply(pval.get(i));
                
                if(temp2.compareTo(val.get(h))==0)
                {
                        strb.append(ch[i]);
                        temp=pval.get(i);
                        i=-1;
                
                        h++;
                        if(h>=l)
                                break;
                        
                }
        }
        }
        
        System.out.print("Case #"+im+": ");
        System.out.println(String.valueOf(strb));
        im++;
                t--;
        }
}
}
                
                

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/e97e508e-d695-4db0-8cfb-f8aa3379574e%40googlegroups.com.

Reply via email to