Program Analysis Jobs

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?

(Note: This program, written in C # language, but as long as there is no reading pressure on the basis of C language, if you do not understand some of the statements, please check yourself)

Write the results of the above questions on the blog, Deadline this Sunday (March 19) 8 o'clock in the evening

Using System;

Using System.Collections.Generic;

Using System.Text;

Namespace Findthenumber

{
Class Program
{
static void Main (string[] args)
{
int [] RG =
{2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
20,21,22,23,24,25,26,27,28,29,30,31};
for (Int64 i = 1; i < int64.maxvalue; i++)
{
int hit = 0;
int hit1 =-1;
int hit2 =-1;
for (int j = 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);
}
}
}
}
}

For:

1. According to the Code analysis, the program defines I as a number: between 2 and 31, only two consecutive numbers can not be divisible by I, the rest of the number is divisible by I, so this number is to remove the two consecutive numbers, all the number of least common multiple.

2. This number I exists. The smallest number that fits this feature I didn't figure out, should be very big, 10^12 above.

3. Running this program on a computer should take a very long time to reach this number. Because it is the least common multiple of the remaining 28 numbers, the program is probably going to perform this least common multiple cycle, and then the calculation time should be at least 10000min.

4. On the web and in the Forum to see the increase in the efficiency of the program, the program can be optimized algorithm to improve operational efficiency. (By reading someone else's blog, I learned that multicore CPUs can also perform the next loop at the same time I perform a loop, which can be almost several times more efficient.) )

Program Analysis Jobs

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.