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);
}
}
}
}
}
这段程序虽然很短,但是我没怎么用过c#,以前用的都是c语言,所以百度了几个不明白的地方。
这段程序我理解的是,这段代码要找出不能被数组rg[]中连续两个数所整除的数。这样的数存在,最小的是1。这就是我看完这段程序所理解的。虽然正确性有很大的不确定,但,我锻炼了阅读他人代码的能力。
最后两个问题,我没有什么头绪。