第三周作业 作业1

阅读下面程序,请回答如下问题:

问题1:这个程序要找的是符合什么条件的数?

问题2:这样的数存在么?符合这一条件的最小的数是什么?

问题3:在电脑上运行这一程序,你估计多长时间才能输出第一个结果?时间精确到分钟(电脑:单核CPU 4.0G Hz,内存和硬盘等资源充足)。

问题4:在多核电脑上如何提高这一程序的运行效率?

 1 using System;
 2 
 3 using System.Collections.Generic;
 4 
 5 using System.Text;
 6 
 7 namespace FindTheNumber
 8 
 9 {
10   class Program
11   {
12     static void Main(string[] args)
13     {
14       int [] rg =
15           {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
16            20,21,22,23,24,25,26,27,28,29,30,31};
17       for (Int64 i = 1; i < Int64.MaxValue; i++)
18       {
19         int hit = 0;
20         int hit1 = -1;
21         int hit2 = -1;
22         for (int j = 0; (j < rg.Length) && (hit <=2) ; j++)
23         {
24           if ((i % rg[j]) != 0)
25           {
26             hit++;
27             if (hit == 1)
28             {
29               hit1 = j;
30             }
31             else if (hit == 2)
32             {
33               hit2 = j;
34             }
35             else
36               break;
37           }
38 
39         }
40         if ((hit == 2)&& (hit1+1==hit2))
41         {
42           Console.WriteLine("found {0}", i);
43         }
44       }
45     }
46   }
47 }

问题1: 要在rg数组中找出一个数,这个数不能被2~31中相邻的两个数的整除,但能被其他28个数整除。

问题2:这是一个非常大的数,百度一下23*33*52*7*11*13*19*23*29*31=2123581660200。16,17与其它28个数字的最小公倍数。这么大的数量级,内心是惊讶的。

问题3:2的63次方为9.223372e18秒.除以3600为2.562048e15时,再除以24*365为2.924712e11年。在有限的生命里不现实。

问题4:在进行运算时,尽量关掉不必要的的进程。减少对cpu的利用。

 

原文地址:https://www.cnblogs.com/123456789-bnm/p/5302354.html