阅读代码
老師給定代碼:
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;}elsebreak;}}if ((hit == 2)&& (hit1+1==hit2)){Console.WriteLine("found {0}", i);}}}} }?
閱讀分析:給定一個30個數字的從2至31的數組,剛開始Int64不太懂什么意思,百度查了下解釋
這樣就大致能理解了,通過for循環遍歷數組直到結束或hit大于2之前,找到不能被整除i的數,hit就++,hit1和hit2中分別保存的是最后兩個不能整除i的數組中的數,如果這兩個數相鄰則輸出i的數值。但是運行程序,等了40分鐘沒出來結果。所以不知道理解的對不對還是運行出錯了
?
轉載于:https://www.cnblogs.com/zhangruiyuan/p/5295643.html
總結
- 上一篇: 多重背包 (poj 1014)
- 下一篇: 3月19