[Projecte1_] projecteuler_040

Source: Internet
Author: User
// 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 */

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.