• c#代码分析


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

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

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

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

    复制代码
     1 using System;
     2 
     3 using System.Collections.Generic;
     4 
     5 using System.Text;
     6 
     7 namespace FindTheNumber
     8 
     9 {
    10   class Program
    11   {
    12     static void Main(string[] args)
    13     {
    14       int [] rg =
    15           {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
    16            20,21,22,23,24,25,26,27,28,29,30,31};
    17       for (Int64 i = 1; i < Int64.MaxValue; i++)
    18       {
    19         int hit = 0;
    20         int hit1 = -1;
    21         int hit2 = -1;
    22         for (int j = 0; (j < rg.Length) && (hit <=2) ; j++)
    23         {
    24           if ((i % rg[j]) != 0)
    25           {
    26             hit++;
    27             if (hit == 1)
    28             {
    29               hit1 = j;
    30             }
    31             else if (hit == 2)
    32             {
    33               hit2 = j;
    34             }
    35             else
    36               break;
    37           }
    38 
    39         }
    40         if ((hit == 2)&& (hit1+1==hit2))
    41         {
    42           Console.WriteLine("found {0}", i);
    43         }
    44       }
    45     }
    46   }
    47 }
    复制代码
    1.说实话我真的没看懂程序,不过不懂得东西百度都懂,哈哈,这个程序主要是找到一个不能被 2~31 中相邻的两个数整除,但可以被其余28个数整除。
    2.23*33*52*7*11*13*19*23*29*31=2123581660200,相邻的两个数为16 17;
    3.运行不出来啊!
    4.可用多线程的方式。
  • 相关阅读:
    hdu 2147博弈找规律
    hdu 1851 巴什博弈
    hdu 1729 sg博弈
    hdu 2516博弈找规律
    (转载)博弈之SG函数
    poj 2234基础Nim博弈||sg博弈
    hdu 1730 sg博弈||nim博弈
    hdu 1847 博弈找规律
    n hdu 1760 [SG博弈]二维状态
    hdu 1849 nim博弈
  • 原文地址:https://www.cnblogs.com/dujuan105/p/5301739.html
Copyright © 2020-2023  润新知