Given is my code in Python 3, It runs for all test cases I tried but when I 
submit, it shows Runtime Error, what could be the possible reason?

import math
import string
def listOfPrimes(n):
    primes = [2,3]
    for i in range(1, int(n/6)+1):
        num = 6*i + 1
        flag = 1
        sqnum = math.sqrt(num)
        for j in primes:
            if(num%j==0):
                flag = 0
                break
            if(j>sqnum):
                break
        if(flag==1):
            primes.append(num)
        num = 6 * i - 1
        sqnum = math.sqrt(num)
        for j in primes:
            if(num%j==0):
                flag = 0
                break
            if (j > sqnum):
                break
        if(flag==1):
            primes.append(num)
    return primes



inp = int(input())
for i in range(inp):
    inp1 = input()
    inp2 = input()
    inp1 = inp1.split(' ')
    num = int(inp1[0])
    nprimes = listOfPrimes(num)
    nprimes.sort()
    inp2 = inp2.split(' ')
    message = [int(j) for j in inp2]

    firstsq = math.sqrt(message[0])
    first = message[0]
    seq = []
    codes = []
    for j in nprimes:
        if(first%j==0):
            codes.append(j)
            break
        if(j>firstsq):
            break
    num2 = int(first/codes[0])
    if message[1]%codes[0] == 0:
        seq.append(num2)
        seq.append(codes[0])
        codes.append(num2)
    else:
        seq.append(codes[0])
        seq.append(num2)
        codes.append(num2)
    for j in range(1,len(message)):
        temp = int(message[j]/seq[j])
        seq.append(temp)
        if(temp not in codes):
            codes.append((temp))

    codes.sort()
    maps = dict(zip( codes, string.ascii_uppercase))

    output = []
    for j in seq:
        output.append(maps[j])
    output = ''.join(output)
    print("Case #" + str(i + 1) + ": " + output)

-- 
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/1541e4e4-1fc7-4a1a-b969-683d8a9a9d3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to