UPD — seems the sieve function in my code caused some undefined behavior since it was getting out of bound, so I have got my answer. Thank you all who came forward to help. (I didn't even needed that function, it was left from the previous code, seems it was my unlucky day, atleast, got to learn something ;-;)
Why did I get runtime error for this code of mine in the competition?
link: https://mirror.codeforces.com/contest/1562/submission/127119400
While the same got accepted just after the competition
link: https://mirror.codeforces.com/contest/1562/submission/127129361
(exact same code)
PS- ;-; I am trying so hard to get better but these types of problem are so demotivating
MikeMirzayanov(edit-removed tag) please do help if possible ( I really don't want to be irritating ranting about my problem everywhere, but you see, this feels a big achievement to me, watching myself getting better everyday, and yes, ratings matter for me, rankings matter for me, it is kind of an adrenaline boost to me, so please help if possible ;-;)
Auto comment: topic has been updated by banjobyster (previous revision, new revision, compare).
I think the issue is legit, the exact same code got an AC that got an RTE previously in the contest. It'd be great if someone from headquarters could review this issue once.
Thank you for commenting :)
Your sieve function contains undefined behaviour (your index goes out of bounds). It seems to me that you should change the line
vi a(n,0);
tovi a(n+1,0);
Thank you for your insight.
Will update that part, but atleast, in this code, this shouldn't have mattered, reason being my solution got accepted just after the contest, I believe so.
When you have undefined behaviour in your code, all bets are off. You just got unlucky with bad RNG during the contest. I just submitted the same code and it passed 6 times and failed the 7th time. Btw. when you get a runtime error, it's probably almost always an out of bounds error, so look for that in the future.
What's funny is that you could have just submitted the same code and probably passed the tests and this meme would actually come true hahaha
Ok, seems I have to accept it and move on, maybe try getting better ;-;
Shall I update the post? Or let it be?
And I mistakenly kept the sieve function, that was from the previous question ;-;
But still that passed but this didn't, and for test case number 35 gave runtime error
Auto comment: topic has been updated by banjobyster (previous revision, new revision, compare).
If you compile with the -D _GLIBCXX_DEBUG and -D _GLIBCXX_DEBUG_PEDANTIC flags, your program will always crash when you run it locally and it gets an out of bounds error. The program will run slower, but it's really worth avoiding the chance of terrible undefined behavior
Thank you so much, this is a really useful tip :D