Second assignment in the third week

Source: Internet
Author: User

Known programs answer questions

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);
}
}
}
}
}

1. What are the criteria for this program?

In the 30 numbers of the RG array, this I can be divisible by the other 28 numbers, but not by the two connected numbers. At first I did not understand the program, referring to the http://blog.csdn.net/jcwKyl/article/details/3889802 after understanding the meaning of the program. This program uses hit, hit1, hit2 to control the output, hit is I% rg[j])! = 0 times, hit1, Hit2 is an array subscript, (hit = = 2) && (hit1+1== HIT2) represents two numbers that cannot be divisible and two consecutive numbers, and outputs if such numbers exist.

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

What the program is looking for is this number: This number I cannot be divisible by two contiguous numbers in the 2-31 30 numbers, but can be divisible by the other 28 numbers. So, this I must be an integer multiple of the other 28 numbers of least common multiple. However, I can not be divisible by two adjacent numbers, so it is necessary to decompose the mass factor or I is not included in the quality factor of the two number of the qualitative factor, or I is the number of qualitative factors less than the number of the same factor in the two number of times. By calculation, the two consecutive numbers that cannot be divisible are 16 and 17. So meet the minimum number of the remaining number of least common multiple, 23*33*52*7*11*13*19*23*29*31=2123581660200.

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).

About 10 minutes.

Second assignment in the third week

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.