zoukankan      html  css  js  c++  java
  • 课后练习题:读程序

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

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

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

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

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

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

    在网上查到的Int64的数据范围是-9223372036854775808~+9223372036854775807

    问题1:这个程序的目的就是寻找一个很大的数,在1-9223372036854775807之间,可以被28位数整除,但是不能被2到31中相邻的数整除,但能整除其他任何数

    问题2:脑洞大开,答案是最小公倍数:2123581660200。

     问题3:预测三四分钟。。。。(我也不确定)

    问题4:将处理器中计算引擎集成

     

     

     

  • 相关阅读:
    快速排序
    C# String.Format
    理解C++ static
    程序地址空间
    map的实现
    【S4】使用empty()而不是判断size()是否为0
    RHEL6.4 NFS文件共享服务器搭建
    使用UDEV绑定ASM多路径磁盘
    MySQL的启动程序
    [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
  • 原文地址:https://www.cnblogs.com/sunle/p/5303495.html
Copyright © 2011-2022 走看看