import math

t=input()

for i in range(1,t+1):

a=input()

b=input()

n=input()

m=(n+1)/2

z=math.pow(2,m)

a=a*z
z=math.pow(2,n-m)
b=b*z

if a>b:

print(int(a/b))

else:

print(int(b/a))

t=input()

for i in range(1,t+1):

a=input()

b=input()

n=input()

m=(n+1)/2

z=math.pow(2,m)

a=a*z
z=math.pow(2,n-m)
b=b*z

if a>b:

print(int(a/b))

else:

print(int(b/a))

You aren’t converting the inputs to integers. When you take input with `input()`

it is saved in the variable in the form of a string. You need to save it as `var = int(input())`

. This converts it to an integer.

1 Like

when you are using input(), this returns string values so you can’t do arithmetic operations on this.if you use

variable=int(input()), this will return integer values so now replace your program with this and this will work for sure

guys it is still giving nzec

**Python** takes the **whole** line as input.

Suppose the input is

```
1 2 3 4 5
```

And you write

```
s = input()
```

Then **s = “1 2 3 4 5”** i.e. the whole string.

If you want the numbers to be **mapped** in different **variables** as **integers**, then you can write

```
a, b, c, d, e = map(int, s.split())
```

Now, **a = 1**, **b = 2**, **c = 3**, **d = 4**, **e = 5**.

If you want the numbers to be stored as **integers** in an **array** (called **list** in **Python**), then you can write

```
arr = list(map(int, s.split()))
```

Now, **arr = [1, 2, 3, 4, 5]**

Keeping the above points in mind, you can now take the input correctly and get rid of **NZEC**.

**NOTE**: The above said points are in reference to **Python** (**PYTH 3.4**)

**UPDATE 1**:

The reason that your current code https://www.codechef.com/viewsolution/14405012 is getting **NZEC** error is that you are **not** converting **string** to **int** while taking input for variable **t**.

The line

```
t = input()
```

Should be changed to this

```
t = int(input()) # remember input() is always a string
```

And you’ll get rid of **NZEC** error.

However, your logic for the problem TWONMS is still faulty and not optimal. You have to multiply **A** and **B** by **2** alternatively for **N** turns, starting form **A**. And, in the end, you have to divide the **max(A, B)** by **min(A, B)**. So, the common **2**’s will get cancelled out.

Therefore, if **N** is **even**, then **A** and **B** will be multiplied by **equal** number of **2**’s and they will get canceled out giving the answer as **max(A, B)** / **min(A, B)**.

If **N** is odd, then **A** will be multiplied by one extra **2** than **B**. So, after cancellation, answer will be **max(2A, B)** / **min(2A / B)**.

Here is your **corrected** code https://ideone.com/KLr1d7

3 Likes

import math

t=input()

for i in range(1,t+1):

#a=input()

#b=input()

#n=input()

#a=int(a)

#b=int(b)

#n=int(n)

s=input()

arr=list(map(int,s.split()))

m=int((arr[2]+1)/2)

z=math.pow(2,m)

arr[0]=arr[0]*z

z=math.pow(2,arr[2]-m)

arr[1]=arr[1]*z

if arr[0]>arr[1]:

print(int(arr[0]/arr[1]))

else:

print(int(arr[1]/arr[0]))

This is the updated code . Still giving nzec . Can somebody help

I suggest running code on codechef IDE where it keeps on telling you the error. The error at this moment is this-

```
File "./prog.py", line 3, in <module>
TypeError: Can't convert 'int' object to str implicitly
```

It means perhaps t is still a string, have you corrected the input for t? After changing that line to- `t=int(input())`

i got some output (no error) so i assume this would be last error you are facing.

Also, having a look at other people’s code for any problem is really recommended, as it solves most of input-output doubts. Thats what i do most of the times

1 Like

I have updated my code and it is working for 30 points . logic seems correct to me however what @c_utkarsh suggested worked for me and I got AC but still what is the problem in my code when it comes to larger constraints . Is it because of overflow which occurs when powers of 2 is calculated or there is some other problem . With this code which i have edited I am getting ac for 30 points and NZEC for the rest 70 . Thanks all .

i am getting NZEC error . This is kinda my first python code so please help

My code is which version ? Im not sure if it is 3.4

The syntax of your code indicates that its Python (PYTH 3.4)

Hey, I’ve updated my answer above. You can go through it to find your mistake(s).

Did you have a look at my answer? It clearly told you the mistake

1 Like

buddy it worked but i have another doubt as well

how to make it correct?

Of course, what is it??

Refer here - https://stackoverflow.com/questions/4050907/python-overflowerror-math-range-error

The number of digits is kind of too much when N is 10^9

Also, even if it didnt gave this error, it will give you a TLE, because you should know, these big numbers take additional operations (and hence time) to calculate/have operations performed on them.

1 Like

You cannot.

Since, 1 <= A,B,N <= 10^9 and according to your code, M <= 5 * 10^8 (almost).

So, A*M can be upto (10^9)*(2^(5 * 10^8)) i.e. almost 150515007 digits. This is too big a number to be stored.

1 Like