http://projecteuler.net/problem=40 [Answer:210]
2011-12-10 11:42
417 查看
#include <iostream> using namespace std; int NthDigit( int n ) { int nNumberLength = 1; int nNumberCount = 9; int nNumberBegin = 1; while ( n > nNumberLength * nNumberCount ) { n -= nNumberLength * nNumberCount; nNumberLength += 1; nNumberCount *= 10; nNumberBegin *= 10; } int nIndex = (n - 1) / nNumberLength; int nNumber = nNumberBegin + nIndex; int times = (nNumberLength - 1) - ((n - 1) - nIndex * nNumberLength); while ( times > 0 ) { --times; nNumber /= 10; } return nNumber % 10; } int main() { int result = 1; result *= NthDigit( 1 ); result *= NthDigit( 10 ); result *= NthDigit( 100 ); result *= NthDigit( 1000 ); result *= NthDigit( 10000 ); result *= NthDigit( 100000 ); result *= NthDigit( 1000000 ); cout << result << endl; return 0; }
相关文章推荐
- http://projecteuler.net/problem=5 [Answer:232792560]
- http://projecteuler.net/problem=14 [Answer:837799]
- http://projecteuler.net/problem=19 [Answer:171]
- http://projecteuler.net/problem=25 [Answer:4782]
- http://projecteuler.net/problem=6 [Answer:25164150]
- http://projecteuler.net/problem=13 [Answer:5537376230]
- http://projecteuler.net/problem=20 [Answer:648]
- http://projecteuler.net/problem=7 [Answer:104743]
- http://projecteuler.net/problem=15 [Answer:137846528820]
- http://projecteuler.net/problem=21 [Answer:31626]
- http://projecteuler.net/problem=8 [Answer:40824]
- http://projecteuler.net/problem=16 [Answer:1366]
- http://projecteuler.net/problem=38 [Answer:932718654]
- http://projecteuler.net/problem=17 [Answer:21124]
- http://projecteuler.net/problem=18 [Answer:1074]
- http://projecteuler.net/problem=23 [Answer:4179871]
- http://projecteuler.net/problem=26 [Answer:983]
- http://projecteuler.net/problem=27 [Answer:-59231]
- http://projecteuler.net/problem=32 [Answer:45228]
- http://projecteuler.net/problem=28 [Answer:669171001]