This was what i did
T=int(input())
l3=[] #to get primee no.
l5=[] #to get final output
s=""
for i in range (0,T):
l1=input().split(" ")
l2=input().split(" ")
n=int(l1[0])
l=int(l1[1])
for j in range (2,n):
if(int(l2[0])%j==0):
f1=j
if (int(l2[1])%f1!=0):
l3.append(j)
else:
l3.append(int(l2[0])//f1)
for j in range(0, l):
r=int(l2[j])//int(l3[j])
l3.append(r)
l4=sorted(l3)
l4 = list(dict.fromkeys(l4))
for j in range(0,len(l3)):
for k in range(0,len(l4)):
if(l4[k]==l3[j]):
s=s+chr(65+k)
continue
l5.append(s)
s=""
l3=[]
l4=[]
for i in range(0, len(l5)):
print("Case #{}: {} ".format((i+1), l5[i]))
I was getting answer in my local compiler but gcj compiler was not
accepting it.
On Sun, Apr 7, 2019 at 9:38 PM Joseph DeVincentis <[email protected]> wrote:
> It is possible when the message starts something like ABA for the first
> two values to be the same. In this case, you get gcd = values[0] instead of
> the prime shared between the first two values, and this wrong calculation
> leads to some of your later numbers being fractions, which probably leads
> to you computing more than 26 different values and then
> alphabets[primes.index(divisors[j])] indexes beyond the length of alphabets.
>
> You have to find the first two values which are different and take their
> GCD to start the process off, and possible wind it both forward and
> backward from that point.
>
> Also, if you use math.gcd() (fractions.gcd() in versions of Python before
> 3.5) instead of your GCD function, it will use the Euclidean algorithm to
> compute GCD which will be fast enough for the hidden input where the primes
> could be up to 100 digits long.
>
>
> On Sun, Apr 7, 2019 at 9:27 AM zombiepunkman <[email protected]>
> wrote:
>
>> I am unable to debug the runtime error in this solution to Cryptopangrams
>> problem.
>> Please help.
>>
>> def gcd(a,b):
>> for i in range(min(a,b),0,-1):
>> if(a % i == 0 and b % i == 0):
>> return i
>>
>>
>>
>> if __name__=='__main__':
>> alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
>> T = int(input())
>> answers = ["" for i in range(T)]
>> for i in range(0,T):
>> N,L = [int(s) for s in input().split(" ")]
>> divisors = []
>> values = [int(s) for s in input().split(" ")]
>> div = gcd(values[0],values[1])
>> divisors.append(int(values[0]/div))
>> divisors.append(div)
>> for j in values[1:len(values)]:
>> div = int(j/div)
>> divisors.append(div)
>> primes = list(set(divisors))
>> primes.sort()
>> for j in range(0,len(divisors)):
>> answers[i] += alphabets[primes.index(divisors[j])]
>> for i in range(0,T):
>> print("Case #{}: {}".format(i+1,answers[i]))
>>
>>
>> Python version 3.6
>>
>> --
>> 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 post to this group, send email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/google-code/53742ecf-7373-4e3b-9e9e-f16717220df2%40googlegroups.com
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> 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 post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/CAMAzhzjm7B82D_Bd6MnCvxXeg8FayvE54Dd34iPSqC2PiTaD4w%40mail.gmail.com
> <https://groups.google.com/d/msgid/google-code/CAMAzhzjm7B82D_Bd6MnCvxXeg8FayvE54Dd34iPSqC2PiTaD4w%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/CAK0Rn6%3DT485XAYP6kFebsu-UufFq%2BnbxijPiou7s5DtgGeEBKA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.