DIVPAIR: Runtime error (NZEC) in python

I already did a search but nothing works, I’m getting runtime error (NZEC) when I submit this code for the Divisible pairs problem in the May long contest. Can you help me?

import sys

def multiples(N,M):
    n = 1
    multiplos = {1:M}
    while n*M <= 2*N:
        multiplos[n] = n*M
        n += 1
    return multiplos

if __name__ == "__main__":
    for entrada in sys.stdin:
        N = int(entrada.split()[0])
        M = int(entrada.split()[1])
        n = 0
        rango = range(1,N+1)
        multiplos = multiples(N,M)
        for x in rango:
            for y in multiplos.values():
                if y-x in rango and x>abs(y-x):
                    n += 1
        print n

providing code about a problem in a running contest seems to be a bad idea, imho. :slight_smile:

hint: N can be quite large. you should check the difference between range and xrange functions. good luck :slight_smile:



Yeah, I also though it was a bad idea, but I couldn’t help it and didn’t found the spoiler tag or something.