Why am I getting Runtime error for this code?

I am trying to solve this question in python FLOW016 Problem - CodeChef but getting Runtime error.Please only help through python codes.Thanks in advance.
MY code is here:

from fractions import gcd
for _ in range(int(raw_input())):
a,b=map(int,raw_input().split())
try:
g=gcd(a,b)
l=int((a*b)/g)
print g,l
except:
print 0,0

2 Likes

raw_input() receives the input as just a string. Use raw_input().split() to convert the string to a list. Else you will have indexing problems, since the spaces given in the input are taken for mapping. So you get the nzec (non-zero exit code) error

Many times it is due to some white places left.

Well a,b are given separated by space so you can give split(’ ') rather than split() and also a,b>=1.

So you may remove try catch block

I edited your code dear-

from fractions import gcd 
for _ in range(int(raw_input())): 
    a,b=map(int,raw_input().split())
    try: 
        g=gcd(a,b) 
        l=int((a*b)/g) 
        print g,l
    except: 
            print 0,0

Please follow exact indentations, Heres what I got on hackerrank compiler after correction-

Compilation Successful
Input (stdin)
3 
120 11
10213 312
10 3
Your Output
1 1320
1 3186456
1 30

Hope it helped :slight_smile:

EDIT1-

From what I noticed, if test case mentioned input as -

1
8
36

Then the WILL face error. But its strange if this is the case, cause input format specifically says cases as

1
8 36

So I am not sure why your codes not working.

(From my experience, your except: was not properly indented. Take care of indentations in Python)

Here the problem is in the test cases. There is some extra whites spaces or extra newline in original test cases otherwise your code is fine but giving WA.

Please try this question on your own by submitting the solution on the given link and then only comment over here.

1 Like

Here the problem is not about indentation or white spaces but the framing of test cases. Test cases is designed in such a way that output will give AC only in the range of int32 rather than int64.

You can conform this by C++ code that was compiled in int data type first and then long long data type.

As you will see that C++32 compiled code gives AC but C++_64 failed and showing WA. So it conform that the problem is in test cases.

You can also conform this in python by considering int32 datatype of numpy module. See here

1 Like

your code is also giving WA. But thanks for your help.

Hmmm…I also think the same

How do you know??

1 Like

add this in Q desc.

EDIT- Its giving error that its “Due to server maintenance we are working in read only mode…” or something.

1 Like

I tried doing the same question with/without space separation but still getting a WA. so it may have some error with the test cases.

1 Like