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:这个程序要找的是符合什么条件的数?

    答:这个程序是找在2到31中,不能连续被两个数整除但能被其他的28个数整除的数。

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

    答:这个数存在,是2123581660200,即除了16,17外的最小公倍数。

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

    答:这个问题对我的水平来说有点难,技术比较活跃。

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

    答:在多核电脑上,我觉得把这个任务分为多个并发执行的进程会提高一定的执行效率。(能力有限,只能理解这么多)

  • 相关阅读:
    zabbix 对/etc/ssh/sshd_config文件的监控 但status为unknowen
    Kotlin从零到精通Android开发
    谷歌官方 构建您的第一个应用 Kotlin版
    android studio 运行按钮为灰色的解决办法之一
    webapi发布到windows 2012的iis8里 出错
    Asp.net MVC WebApi项目的自动接口文档及测试功能打开方法
    Asp.net Web Api开发(第四篇)Help Page配置和扩展
    关于SNMP的MIB文件的语法简述
    Visual Stdio 2017增加SVN支持
    ffmpeg 多个音频合并 截取 拆分
  • 原文地址:https://www.cnblogs.com/ruiguo/p/5624391.html
Copyright © 2011-2022 走看看