NUMFACT Wrong Answer

Hello,
I am trying to solve NUMFACT, but it is giving me Runtime Error NZEC
My code seems to run perfectly fine for all cases I can think of but it is giving me an NZEC in cases after the first case in subtask 1.
Submission link

import math
T = int(raw_input())

for i in range(T):
    raw_input()
    p = [int(_) for _ in raw_input().split(" ")]
    p1 = 1
    for p_ in p:
    	    p1 *= p_
    facs = 2
    sqr = int(math.sqrt(p1))
    for j in range(2, sqr+1):
	    if p1%j==0: facs+=2
    if sqr*sqr==p1: facs-=1
    print facs

Please tell me what cases I’m missing.

@svineet : You are having integer overflow .

Constraints :

1 ≤ N ≤ 10

2 ≤ Ai ≤ 1000000

So product of all numbers can go out of range for int .

Hence it may become negative also .

So when you take square root you get run time error .

there is no limit on ints in python.

@svineet : Try this test case

1

5

1000000 10000000 1000000 10000000 1000000

Your program gives

Traceback (most recent call last):

File “prog.py”, line 12, in

OverflowError: range() result has too many items

Line 12 of your program is

for j in range(2, sqr+1):

Each number can be 10^6 and there can be 10 numbers so product can be 10^60 .

Square root of 10^60 is 10^30

You can’t iterate over these many numbers .

You have to improve your logic

I have done this problem , so i can tell you the logic , but don’t want to spoil your fun solving it .

So I will give you the logic if you request .

Best of luck , Happy Coding .

PS : Sorry about earlier wrong comment , I haven’t used python that’s why i was not aware of this.

1 Like

no need for the logic, after all the fun is in figuring it out ourself :slight_smile: