The teacher assigned a reading program this week.
The problem is as follows:
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); } }}}
1, through the analysis can be known that the code hit in the number of numbers can not be divisible by the amount of I, hit1 for the first time not divisible by the number of subscript, the same hit2 for the second can not be divisible by the number of subscript. The last if judgment shows that the number I should be looking for is not divisible by only two numbers in the array, and the two numbers are adjacent to the array. 2, on the Internet to check the next, the value of Int64.maxvalue is 18446744073709551615. I am not sure if such a number exists, I have been running for a long time without a result, for the moment I can not find the results. 3, due to the excessive number of cycles, as well as the limitations of my knowledge, the time complexity of the program is O (n), but the exact time is not determined. 4, the knowledge is limited, do not know how to improve efficiency.
Third Week Job---reading program