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

×

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

asked 06 Jun '12, 14:24

topazbravo's gravatar image

2★topazbravo
1122
accept rate: 0%

add some simple code that end with runtime error

(06 Jun '12, 14:27) betlista ♦♦3★

why are you posting the same question twice??

(06 Jun '12, 15:01) ashhar244★

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

link
This answer is marked "community wiki".

answered 17 Sep '16, 01:20

saimurali333's gravatar image

2★saimurali333
11
accept rate: 0%

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

link

answered 17 Sep '16, 05:25

yougaindra's gravatar image

2★yougaindra
913
accept rate: 0%

edited 17 Sep '16, 20:13

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 !

link

answered 06 Apr '17, 12:25

karan10xb's gravatar image

2★karan10xb
11
accept rate: 0%

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.

link

answered 06 Apr '17, 13:44

lagnam's gravatar image

1★lagnam
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×678
×169
×30

question asked: 06 Jun '12, 14:24

question was seen: 2,981 times

last updated: 06 Apr '17, 13:44