Third week assignment 2

Source: Internet
Author: User

To read the following procedure, please answer the following questions:

Question 1: What are the criteria for this program?

Question 2: Does such a number exist? What is the minimum number that meets this condition?

Question 3: How long do you expect to be able to output the first result when running this program on a computer? The time is accurate to minutes (computer: Single core CPU 4.0G Hz, memory and hard disk resources are sufficient).

Question 4: How can I improve the efficiency of this program on multi-core computers?

usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespacefindthenumber{classProgram {Static voidMain (string[] args) {            int[] RG =            {2,3,4,5,6,7,8,9,Ten, One, A, -, -, the, -, -, -, +,  -, +, A, at, -, -, -, -, -, in, -, to};  for(Int64 i =1; i < Int64.maxvalue; i++)            {                intHit =0; intHit1 =-1; intHit2 =-1;  for(intj =0; (J < RG. Length) && (hit <=2); J + +)                {                    if((i% rg[j])! =0) { hit++; if(hit = =1) {hit1=J; }                        Else if(hit = =2) {Hit2=J; }                        Else                             Break; }                }                if(hit = =2) && (hit1 +1==hit2)) {Console.WriteLine ("found {0}", i); }            }        }    }}

Personal understanding: First define the shaped array RG "2~31", the target number divided by the array rg in sequential two element remainder is not equal to 0, divided by the remainder of the other elements equals 0. Such a number should exist, but very large, the query data is not the result, but can be expected to run the program directly, I am afraid even if only the first number will take a long time. Running this program on the computer, the computer CPU frequency 4.0g, Operation 4*2^30 Times per second, the first result should be (30-2) the number of least common multiple, should be very large, the calculation of the program is also very large, is expected to calculate more than 120min. Optimize the program on multicore computers and invoke multiple cores to traverse at the same time to improve operational efficiency.

Third week assignment 2

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.