fork download
  1. # your code goes hereimport sys
  2. import math
  3.  
  4. primes = []
  5.  
  6. def gcd(a, b):
  7. if a == 0:
  8. return b
  9. return gcd(b % a, a)
  10.  
  11. if __name__ == "__main__":
  12. t = int(input())
  13. # print(gcd(10**100, 10**87), "<--")
  14. for t_ in range(1, t + 1):
  15. print("Case #", t_,": ", end = '', sep = '')
  16. n, l = [int(x) for x in input().strip().split(' ')]
  17. ar = [int(x) for x in input().strip().split(' ')]
  18. factors = []
  19. for i in range(l - 1):
  20. factors.append(gcd(ar[i + 1], ar[i]))
  21. factors = [ar[0] // factors[0]] + factors
  22. factors = factors + [ar[-1] // factors[-1]]
  23. factors_ = list(set(factors))
  24. factors_.sort()
  25. for i in range(len(factors_)):
  26. if factors_[i] <= 1:
  27. del factors_[i]
  28. i -= 1
  29. my_dict = {}
  30.  
  31. for i in range(26):
  32. my_dict[factors_[i]] = chr(ord('A') + i)
  33.  
  34. # assert len(factors_) == 26
  35.  
  36. # print(factors_)
  37.  
  38. for i in factors:
  39. print(my_dict[i], end = '')
  40. print()
  41.  
  42.  
Success #stdin #stdout 0.02s 27704KB
stdin
2
103 31
217 1891 4819 2291 2987 3811 1739 2491 4717 445 65 1079 8383 5353 901 187 649 1003 697 3239 7663 291 123 779 1007 3551 1943 2117 1679 989 3053
10000 25
3292937 175597 18779 50429 375469 1651121 2102 3722 2376497 611683 489059 2328901 3150061 829981 421301 76409 38477 291931 730241 959821 1664197 3057407 4267589 4729181 5335543

  
stdout
Case #1: CJQUIZKNOWBEVYOFDPFLUXALGORITHMS
Case #2: SUBDERMATOGLYPHICFJKNQVWXZ