 Imp thing in Python 3.5

I was working on problem from like past day, I got WA in c++ in couple of test cases, as a result I switched to Python 3. 6 and that’s where I found a thing which can give you WA frequently. It is related to large numbers.
For eg:
`py print((2001100545* 2001100544)/2)`
will print `2.0022016945990984e+18`
and doing it modulo with 10**9 + 7 will give `583686608.0`.

But if we do so with C++ or python 2x…
it will give `584787011`.

See the difference ^^.
In such cases python 2x will returns right answer because it have long type and interpreter automatically decides, which type i.e. `int` or `long` is to be used.

1 Like

This is because you did not use the mod correctly. For (nm) , you must do ((n%mod)(m%mod))%mod. You should get the correct answer.

This will only solve problem if there is modulo.
What about difference betweeen `2.0022016945990984e+18` and `2002201694599098240`.
Obviously, `print(2002201694599098240==2.0022016945990984e+18)` will return `False`

1 Like

You are wrong. ‘/’ in python 3 does normal division and not integer division. For integer division you have to use ‘//’.

6 Likes

/ and // matters 4 Likes

2.00e+18 something like this is called scientific notation
it showing u how the number is stored
it wont return false coz while comparing it will compare original values
as far as to solve the prob do as said by @koulick424
py do mind data type. Hence u can store larges values
but c++ does min. so u need to take care of it

Thanks for sharing.
It was very helpful for me

thank u so much for your help…