Sum of digits in C#
You could do it arithmetically, without using a string: sum = 0; while (n != 0) { sum += n % 10; n /= 10; }
You could do it arithmetically, without using a string: sum = 0; while (n != 0) { sum += n % 10; n /= 10; }
I’m not sure who is still paying attention to this thread, but here goes anyway. First, in the official-looking linked version, it only has to be 1000 factorial, not 10000 factorial. Also, when this problem was reused in another programming contest, the time limit was 3 seconds, not 1 second. This makes a huge difference … Read more