HELP-Getting runtime error in PTUPLES

  1. [Solution: 41904873 | CodeChef] (Solution: 41904873 | CodeChef)(runtime error)
  2. https://www.codechef.com/viewsolution/41904929 (Accepted)
    Can anyone tell why first one resulted in Runtime error when submitted?
    The difference between both solution is in line 18 and 21.
    • prime=sieve(10000001)
    • prime=sieve(1000001)

However , I’m not getting any error for smaller values in my pc as well as codechef ide.

Hey in this solution [Solution: 41904873 | CodeChef], you made a mistake in declaring the count array. Because, you declared count as [0] * (10^7) and not [0] * (10^7 + 1) (Arrays are indexed starting from zero! (Read the symbol “^” as power, not XOR, just clarifying). This solution will run just fine if you declare count = [0] * (10^7 + 1). Check my solution here [Solution: 41907954 | CodeChef]. Check Line 20 in your Error solution with Line 22 in my AC solution)

The reason why your second solution got accepted is that, though you did the same mistake of declaring the count array of size 10^7, you had exactly 10^6 values in the array and your for loop at the end of your code ran till 10^6.

Also, the limits were till 10^6, but you declared count array of size 10^7+1 (That’s not a mistake though! It worked just fine! I’m just letting you know to have a look at the constraints in the question to solve efficiently, so that your code doesn’t get TLE’d).

Cheers!

Thanx Buddy

1 Like