I have tried to implement the Sieve of Eratosthenes to find out the prime nos. in a given range of numbers but it has been having a runtime error . Here’s the code : http://www.codechef.com/viewsolution/1967778
segmentation fault is at line number 12. at line 12, value of i is m. but you cannot access list[m] as list is declared as an array of dimension m (0 to m-1).
rectified the above problem along with some changes in the code . the algorithm still being the same, It’s still putting up a runtime error.Here’s the modified code: CodeChef: Practical coding for everyone …unable to figure out the segmentation violation in this code
@piyukr…you are declaring an array of size more than allowed inside the function…i.e. list[m+1] which is main cause behind the SIGSEGV error.if you want to declare a big value like 10^6 size array then you should declare it out of the function i.e. globally.
but in the case if you declare a array of size 10^9 then it will not allowed…there you must rectify your problem for given domain .as clear by problem n-m=100000…this is the main key.
I have rectified the above problem and made some changes in the code . the algorithm still being the same, It’s still putting up a runtime error.Here’s the modified code: CodeChef: Practical coding for everyone
…unable to figure out the segmentation violation in this code
you second solution is giving runtime for inputs like 1 1000000 (for large values)…and your first solution is failing due to list[i] instead of list[j] in 12th line