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/fd2131db-c593-4a26-9064-82397f70a52d%40googlegroups.com.