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.   存在;最小为数组中的数除16和17外的最小公倍数2123581660200 .

    3.   外循环执行了2123581660200次,执行一次外循环内循环执行大约12次,参考电脑配置,执行一次%用80个周期,所以执行时间约为:2123581660200*12*80/(4*10^9*60)=8500min 。

    4.   同时对n个i进行操作,大大提高程序执行速度。

    注:一开始认为不能被整除的只有连续的两个质数2,3但如果这样这个数就不会存在。经过与同学的交流得到思路。连续的两个数只能是16和17。(程序执行时间参考了薛鹏飞的博客)

  • 相关阅读:
    发布 Rafy .NET Standard 版本 Nuget 包
    使用 MarkDown & DocFX 升级 Rafy 帮助文档
    apache2服务器支持cgi功能
    百兆网口与千兆网口速率协商不成功
    ubuntu etho0 up cron
    linux 后台进程
    MySQL的事务性
    linux下visual studio code配置c++调试环境实例
    linux下visual studio code中gdb调试文件launch.json解析
    Zookeeper安装后,编译C client时报错"syntax error near unexpected token `1.10.2"
  • 原文地址:https://www.cnblogs.com/wangxinliang/p/5295637.html
Copyright © 2011-2022 走看看