problem with large inputs

guys help me out here ,whenever there is an input that is order of 10^6 or 10^9 my compiler says runtime error…when i check the solution like in the ‘ODD’ problem one guy has used character array and then converted them into integers…i mean how do i handle large inputs

It is more easy when you go for python.If it is c there is an algorithm to handle it mostly we handle it using char for more information read the links
http://gd.tuwien.ac.at/languages/c/programming-bbrown/c_055.htm
http://www.azillionmonkeys.com/qed/userInput.html

In problem ODD, you are getting Runtime Error most probably because you are using too much memory by declaring an array of size 10^9.There is not enough memory in your machine(even online judges have a limit on memory your program uses) to accommodate an array of that size. Read this: http://stackoverflow.com/questions/216259/is-there-a-max-array-length-limit-in-c
Ideally, try to declare an array of size less than or equal to 10^7 and that too globally because in some cases array of size 10^7 in any function may exceed stack size and give an error. BTW in the question you mentioned it’s not even necessary to declare array of any size

if the inputs are very large , say order of 10^9 or 10^10 and if you perform some opeartions on these numbers such as addition or multiplication then it is possible that the resulting number may be very large , say order of 10^15 or 10^20. in that case you should take the number as string and then perform operation on strings. very large numbers can be easily stored in string formats.
You could also use BigInteger class in java for handling such numbers.
This could possibly resolve the runtime error !

1 Like

For values of order 10^6 or 10^9 then you can use long or long long or unsigned long long. This will help you.But of order greater than 10^15 u need to take that input as a string.

add some simple code that end with runtime error

why are you posting the same question twice??

thanks for the help. really useful.