Originally Posted by
laserlight
To be fair, the rules in a "competition" are different from the normal rules of programming/software engineering, so I would accept gets() in this case since the input is guaranteed to be correct. Likewise, atoi() is acceptable even though there is no way to check for a parse error.
EDIT:
Yes, if empirical evidence shows that they are effectively equivalent in timing then one might as well use fgets().
There are many such algorithms, but I believe there is none for the general case other than by computing the remainder.