NUMFACT - Where the difference is coming.

import math
def factorize(n):
factors = []
number = n
factor = 2

    while number > 1:
        factor = nextp(number, factor)
        factors.append(factor)
        number /= factor
    return factors
 
 
def nextp(n, f):
    if n % 2 == 0:
        return 2
    for x in xrange(max(f, 3), int(math.sqrt(n) + 1), 2):
        if n % x == 0:
            return x
    return n



def primes(n):
    if n<=2:
        return []
    sieve=[True]*(n+1)
    for x in range(3,int(n**0.5)+1,2):
        for y in range(3,(n//x)+1,2):
            sieve[(x*y)]=False

    return [2]+[i for i in range(3,n,2) if sieve[i]]

a = primes(1001)

def factors(n):
    b = []
    q = 0
    dummy = n
    while n>1:
        while n%a[q]==0:
            b.append(a[q])
            n = n/a[q]
        q+=1
    return b

t = input()
for i in xrange(t):
    n = input()
    z = map(int,raw_input().split())
    
    d = {}
    for j in z:
        dum = factorize(j)
        for q in dum:
            if q in d:
                d[q]+=1
            else:
                d[q] = 1
    
    
        
    print reduce(lambda x, y: x * y,[d[x] + 1 for x in d])

If i’m using the factorize method i’m getting it AC(accepted) but if i use the factors method i’m getting WA(Wrong Answer) for large input and AC for small input, you can see both are doing the same thing but why the difference.