I believe this to be an ACM question from either 96' or 97'
bool nonzerodigit(constunsigned int& n, unsigned int& result)
if (n > 100000) returnfalse;
unsignedint result = 1;
for (unsignedint i = 1; i <= n; ++i)
unsignedint f = i;
while (0 == (f % 5))
f /= 5;
result /= 2;
result = (result % 100000) * f;
result %= 10;
100000 is an upper sanity bound and also a quantizer for the minimum required 6 "least significant" digits.
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
Last Visit: 31-Dec-99 18:00 Last Update: 5-Jul-15 1:12