// Problem 40 // 28 March 2003 // an irrational decimal fraction is created by concatenating the positive integers: // 0. 123456789101112131415161718192021... /// it can be seen that the 12th digit of the fractional part is 1. /// if DN represents the nth digit of the fractional part, find the value of the following expression. /// D1 D10 d100 d1000 d10000 d100000 d000000 # include <iostream> # include <windows. h ># include <ctime> using namespace STD; //************************************// method: getnumposition // fullname: getnumposition // describe: obtains the number of digits from the low position to the high position of num. The position starts from 0. // access: Public // returns: int // qualifier: // parameter: int num // parameter: int position //************************************ int getnumposition (INT num, int position) {for (INT I = 0; I <position; ++ I) {num/= 10;} return num % 10;} void F1 () {cout <"Void F1 ()" <Endl; large_integer timestart, timeend, freq; queryperformancefrequency (& freq); queryperformancecounter (& timestart); int position = 1; // The position to be searched. Each time it is multiplied by 10 const int max_position = 1000000; // the maximum position is int currentnum = 1; // The current number int currentnumlength = 1; // int nextincrese = 10; // The value of the next carry-in is int currentposition = 1; // The current position int result = 1; // product result while (position <= max_position) {// if the position to be searched is reached if (currentposition> = position) {result * = getnumposition (currentnum, currentposition-position); position * = 10;} // current count + 1 + + currentnum; // if the number of digits increases, the length is + 1 If (currentnum = nextincrese) {++ currentnumlength; nextincrese * = 10;} // Add currentposition + = currentnumlength;} cout <"Result:" <result <Endl; queryperformancecounter (& timeend); cout <"Total milliseconds is" <(double) (timeend. quadpart-timestart. quadpart) * 1000/freq. quadpart <Endl; time_t currenttime = Time (null); char timestr [30]; ctime_s (timestr, 30, effecttime ); cout <Endl <"by godmoon" <Endl <timestr;} // main function int main () {F1 (); Return 0 ;} /* void F1 () results in 210 total milliseconds is 2.29293by godmoonwed Apr 11 12:02:55 2012 */