C++编程之美-数字之魅(代码清单2-38(C#代码))

2022-11-30 08:51:13 浏览数 (1)

代码清单2-38(C#代码)

代码语言:javascript复制
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#

0 人点赞