zoukankan      html  css  js  c++  java
  • 阅读程序,回答问题

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

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

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

    答:程序要找的就是在数组里面选两个连续的数,不能被rg数组中相邻的两个数整除,且能被其的数整除。

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

    答:存在,2123581660200

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

    答:这个有点难,还没运行出结果

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

    答:减少其他程序的运行,减少外界设备的连接,多内核是指在一枚处理器中集成两个或多个完整的计算引擎(内核)多核电脑可以在同时执行几个运算操作,这样可以大大的提高程序执行速度。

  • 相关阅读:
    树形dp入门
    D. Kilani and the Game(多源BFS)
    C. Ayoub and Lost Array
    poj3254(状压dp)
    CodeForces
    链式前项星(模板)
    “东信杯”广西大学第一届程序设计竞赛(同步赛)H
    最小生成树kruskal模板
    hdu-4763(kmp+拓展kmp)
    poj-3080(kmp+暴力枚举)
  • 原文地址:https://www.cnblogs.com/majingjing/p/5546349.html
Copyright © 2011-2022 走看看