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。(程序执行时间参考了薛鹏飞的博客)

  • 相关阅读:
    序列化模块
    验证码作业
    Red Hat Enterprise Linux 6安装好,开启网卡到搭建tftp服务器和安装dnw驱动,安装samba服务器
    3.Java基础_Java变量
    2.Java基础_Java常量
    1.Java基础_Java核心机制简介
    1.Python网络编程_UDP(简略版)
    3.Python爬虫入门_正则表达式(简单例子)
    2.Python爬虫入门_requests
    1.Python爬虫入门_urllib
  • 原文地址:https://www.cnblogs.com/wangxinliang/p/5295637.html
Copyright © 2011-2022 走看看