Here's My Solution 

import java.math.BigInteger;
import java.util.*;

public class Solution
{

    public static final Integer len = 105;
    public static BigInteger[] num = new BigInteger[len];
    public static BigInteger[][] fj = new BigInteger[len][2];
    public static Integer T = 0;
    public static BigInteger N = null;
    public static Integer n = 0;

    public static Scanner cin = null;

    public static void ReadForOne()
    {
        N = cin.nextBigInteger();
        n = cin.nextInt();
        for(Integer i = 1; i <= n; ++ i) num[i] = cin.nextBigInteger();
    }

    public static String Solve()
    {
        String ans = "";

        Integer label = 0;
        for(Integer i = 1; i < n; ++ i) if(!num[i].equals(num[i + 1])) 
{label = i; break;}
        BigInteger f1 = num[label].gcd(num[label + 1]);
        fj[label][1] = f1; fj[label][0] = num[label].divide(f1);
        for(Integer i = label - 1; i >= 1; -- i)
        {
            fj[i][1] = fj[i + 1][0];
            fj[i][0] = num[i].divide(fj[i][1]);
        }
        for(Integer i = label + 1; i <= n; ++ i)
        {
            fj[i][0] = fj[i - 1][1];
            fj[i][1] = num[i].divide(fj[i][0]);
        }
        Set<BigInteger> s = new HashSet<>(); s.clear();
        Map<BigInteger, Integer> m = new HashMap<>(); m.clear();
        for(Integer i = 1; i <= n; ++ i)
        {
            s.add(fj[i][0]);
            s.add(fj[i][1]);
        }
        List<BigInteger> lis = new ArrayList<>(); lis.clear();
        for(BigInteger p : s) lis.add(p);
        Collections.sort(lis);
        for(Integer i = 0; i < 26; ++ i) m.put(lis.get(i), i);
        for(Integer i = 1; i <= n; ++ i) ans += (char)(m.get(fj[i][0]) + 
65);
        ans += (char)(m.get(fj[n][1]) + 65);

        return ans;
    }

    public static void main(String[] args)
    {
        cin = new Scanner(System.in);
        T = cin.nextInt();
        for(Integer cas = 1; cas <= T; ++ cas)
        {
            System.out.print("Case #" + cas.toString() + ": ");
            ReadForOne();
            System.out.println(Solve());
        }
    }
}


On Monday, 23 March 2020 05:32:04 UTC+5:30, mostafa albana wrote:
>
>
> import java.io.BufferedReader;
> import java.io.InputStreamReader;
> import java.math.BigInteger;
> import java.util.Arrays;
> import java.util.HashMap;
> import java.util.HashSet;
> import java.util.Map;
> import java.util.Scanner;
>
>
> public class Solution {
>
>
>     private static final char[] ALPHAPET = "abcdefghijklmnopqrstuvwxyz".
> toUpperCase().toCharArray();
>
>
>     public static void main(String[] args) {
>
>
>         try (Scanner scanner = new Scanner(new BufferedReader(new 
> InputStreamReader(System.in)))) {
>             int testCount = scanner.nextInt();
>             for (int testNumber = 1; testNumber <= testCount; testNumber
> ++) {
>                 int maxPrime = scanner.nextInt(); // not working for the 
> large dataset
>                 int seqLength = scanner.nextInt();
>                 int[] seq = new int[seqLength]; // not working for the 
> large dataset
>                 for (int i = 0; i < seqLength; i++) {
>                     seq[i] = scanner.nextInt(); // not working for the 
> large dataset
>                 }
>                 String result = solve(maxPrime, seq);
>                 System.out.println("Case #" + testNumber + ": " + result);
>             }
>         }
>     }
>
>
>     static String solve(int maxPrime, int[] seq) {
>
>
>         HashSet primes = new HashSet();
>
>
>         int[] valuesExpanded= new int[seq.length + 1];
>
>
>         BigInteger commonBigInt = BigInteger.valueOf(seq[1]).gcd(
> BigInteger.valueOf(seq[0]));
>         int number1 = seq[0] / commonBigInt.intValue();
>         int common = commonBigInt.intValue();
>
>
>         primes.add(number1);
>         primes.add(common);
>         valuesExpanded[0] = number1;
>         valuesExpanded[1] = common;
>
>
>         for (int i = 1; i < seq.length; i++) {
>             valuesExpanded[i+1] = seq[i]/common;
>             common = valuesExpanded[i+1];
>             primes.add(common);
>         }
>
>
>         Integer[] sortedPrimes = new Integer[primes.size()];
>         primes.toArray(sortedPrimes);
>
>
>         Arrays.sort(sortedPrimes);
>
>
>         Map<Integer, Character> dictionary = new HashMap<>();
>         for (int i = 0; i < sortedPrimes.length; i++) {
>             dictionary.put(sortedPrimes[i], ALPHAPET[i]);
>         }
>
>
>
>
>         char[] decoded = new char[valuesExpanded.length];
>         for (int i = 0; i < valuesExpanded.length; i++) {
>             decoded[i] = dictionary.get(valuesExpanded[i]);
>         }
>
>
>
>
>         return  String.valueOf(decoded);
>
>
>     }
> }
>
>

-- 
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/5f96912f-2e47-492c-a75b-2d4a4c0be3b8%40googlegroups.com.

Reply via email to