You are not logged in. Please login at to post your questions!


AVGPR last subtask is failing :/

My last subtask is failing in Java but the same approach is working completely fine in python. Help me in finding out the mistake please!

asked 20 Apr '18, 02:22

kunal12's gravatar image

accept rate: 0%

It is due to overflow. Use appropriate data type. e.g. test case - 1 100000 1 1 1 1 1 ...... Your code gives 704982704 instead of 4999950000.

Your approach is working fine in python because python does not allow overflow.


answered 20 Apr '18, 02:39

aryanc403's gravatar image

accept rate: 10%

edited 20 Apr '18, 03:35


Correction :p

Python does not allow overflow till $\approx {10}^{7000}$. Been there, done that, hence the knowledge xD

(20 Apr '18, 22:02) vijju123 ♦♦5★

This upper limit I didn't knew. @vijju123 Thanks.

(20 Apr '18, 22:14) aryanc4035★

I don't think that's correct @vijju123. The documentation clearly states "Integers have unlimited precision"

(20 Apr '18, 23:07) meooow ♦6★

Yes, that 7000 limit holds for float data type I see. If you try to execute-


you will get an overflow error. And for some reason I feel float is the favorite data type of python xD. Yes, integers, I agree with you. Integers do have precision limited to your computer's hardware capacity :p (lets not throw unlimited here :p ). For codechef I think it will be time limit though, instead of memory one.

The thing was, I see this is a general misconception in python where people try to store and manipulate numbers with as long as ${10}^{9}$ digits just because of "unlimited"

(20 Apr '18, 23:42) vijju123 ♦♦5★

@vijju123 which problem used that large value,link please


answered 21 Apr '18, 00:11

des1997's gravatar image

accept rate: 0% But I will recommend doing this problem without using python/ BigInt java or any similar library file.

(21 Apr '18, 00:31) aryanc4035★ - this one. If you try doing brute force with python, thinking that there is no limit, you get NZEC here.

(21 Apr '18, 19:29) vijju123 ♦♦5★

But @vijju123 this question cannot be passed using Brute force. And without Brute force. This question does not require big nos.

(21 Apr '18, 19:56) aryanc4035★

I cant find the question link, but one user tried to do something on lines of $\frac{A*{2}^{(N+1)/2}}{B*2^{N/2}}$ and he got NZEC error. Just search this "twonm" on forum and you will see people using JAVA big integer library to solve it. I call that "Brute Force" since you are doing what the question said xD

(21 Apr '18, 20:10) vijju123 ♦♦5★

I tried doing brute force using python. I got 30 pts and TLE but did not got NZEC.

(21 Apr '18, 20:44) aryanc4035★

As long as we are working with integers no error is thrown e.g. writing (1000000)**1000 is working fine. Whereas writing (10.0)**1000 shows NZEC OverflowError: (34, 'Numerical result out of range')

(21 Apr '18, 21:43) aryanc4035★

so twonm is most solved in june lunchtime and still interesting,nice:)

(26 Apr '18, 22:43) des19972★
showing 5 of 7 show all
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 20 Apr '18, 02:22

question was seen: 438 times

last updated: 26 Apr '18, 22:43