阅读代码

这次是阅读他人的代码,虽然与c不同,但思想是相通的,代码如下

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

我的理解为,给定一个整数数组,大小是30个整数,从2~31,i从1到int64.maxvalue,找出一个i的值,找出的i应该满足i除上数组中的一些元素直到hit=3为止,且余数不为0的数组元素的下标要相邻,遍历完所有数组元素后输出i,但我算出的hit=3,不满足程序中if的条件,我在电脑上运行并没有输出结果,这样的数是否存在我还真不敢下定论,至于如何提高这一程序运行效率我还不太清楚,但我会继续努力,争取早日找到解决方法的。

原文地址:https://www.cnblogs.com/wangzongjie/p/5294940.html