Elysia, gets() is dangerous and atoi() may fail. You're correct on this. I know that. But this discussion is about to find the fastest solution for a given problem. So let's concentrate on that and try to improve the work of the people that posted solutions before.
You may call it evil, but after all, my replacements of scanf() and atoi() are the most significant improvements that were made yet, aren't they?