帐号 自动登录 找回密码 密码 欢迎注册
 搜索

# [讨论] 在上限不大于 1 亿的、公差为5的等差数列中，能否找到100个连续合数？

### 马上注册，结交更多好友，享用更多功能，让你轻松玩转社区。

x

1. lst = Table[1 + 5 (n - 1), {n, 100000000}];
2. w = 95;
3. For[i = 1, i <= 1000000, i++,
4. a = Take[lst, {i, i + w - 1}];
5.      u = 1;
6.    For[k = 1, k <= w, k++,
7.     If[PrimeQ[a[[k]]] == False , m = 1, m = 0];
8.   u = u*m;
9.   ];
10. If[u == 1, Print[a]];
11. ]

 本帖最后由 zeroieme 于 2017-5-18 08:05 编辑 -------------------------

 认真看下面两个帖子，学会用MMA的思维来编写程序，这样你的程序会更加简洁高效。 http://tieba.baidu.com/p/5104865347 http://tieba.baidu.com/p/3194440 ... p;cid=0#54596777549

### 点评

 Select[Split[Select[Range[1, 100000000, 10], PrimeQ], #2 - #1 > 500 &],  Length[#] > 1 &]复制代码输出首尾素数： {{7929491, 7930031}, {9775771, 9776281}, {11066921,   11067491}, {11300411, 11300941}, {11842001, 11842561}, {13167251,   13167841}, {13817561, 13818071}, {13943351, 13943971}, {15719021,   15719531}, {17904361, 17904871}, {18719791, 18720431}, {18980561,   18981121}, {19981361, 19981891}, {20494651, 20495171}, {21235111,   21235631}, {21850181, 21850721}, {22964101, 22964611}, {26318011,   26318521}, {26512531, 26513041}, {26972681, 26973251}, {27334301,   27334841}, {27449711, 27450251}, {27465961, 27466501}, {28189241,   28189751}, {30363631, 30364151}, {31278701, 31279231}, {31419811,   31420381}, {31857151, 31857821}, {34496611, 34497191}, {34610671,   34611341}, {35267861, 35268391}, {35803421, 35803931}, {36571261,   36571841}, {36657961, 36658561}, {39493061, 39493631}, {39569801,   39570361}, {40106581, 40107181}, {41242501, 41243011}, {41300101,   41300641}, {41352301, 41352881}, {41398001, 41398531}, {41614721,   41615251}, {41766421, 41766961}, {42402551, 42403121}, {43011191,   43011701}, {43421351, 43421881}, {45064361, 45064891}, {45309521,   45310051}, {45784771, 45785281}, {46895491, 46896041}, {47065531,   47066051}, {47465651, 47466241}, {48145891, 48146411}, {48783061,   48783611}, {49443451, 49443971}, {49641961, 49642531}, {50357701,   50358251}, {50384011, 50384671}, {50823581, 50824091}, {50983531,   50984041}, {51169291, 51169841}, {51443891, 51444611}, {51530351,   51530951}, {52015591, 52016101}, {52486471, 52487021}, {52946071,   52946591}, {52967171, 52967741}, {53153831, 53154341}, {53521901,   53522551}, {53729681, 53730221}, {53751091, 53751611}, {54186521,   54187151}, {54445591, 54446111}, {54581041, 54581581}, {54760471,   54761051}, {54881951, 54882521}, {54996391, 54996961}, {55294991,   55295521}, {55333631, 55334171}, {55471531, 55472161}, {55857671,   55858291}, {55978781, 55979431}, {56473511, 56474021}, {56588681,   56589251}, {56593081, 56593651}, {57021241, 57021781}, {57138181,   57138691}, {57271561, 57272191}, {57288571, 57289091}, {57444991,   57445501}, {57542531, 57543041}, {57795911, 57796421}, {57844861,   57845471}, {58076911, 58077431}, {58106371, 58106891}, {58432921,   58433461}, {58574111, 58574651}, {58935271, 58935781}, {60060251,   60060841}, {60327161, 60327811}, {61723091, 61723681}, {62183761,   62184281}, {62234891, 62235451}, {62407511, 62408041}, {63396481,   63397121}, {63921001, 63921511}, {64291571, 64292201}, {64425721,   64426231}, {65264461, 65265041}, {65554751, 65555261}, {65597801,   65598341}, {65700961, 65701621}, {65740331, 65740841}, {65995471,   65995981}, {66082001, 66082531}, {66728521, 66729071}, {67027201,   67027711}, {68447201, 68447941}, {68692891, 68693441}, {69953621,   69954151}, {70275641, 70276301}, {70400851, 70401361}, {70493791,   70494301}, {71076931, 71077471}, {71246821, 71247361}, {71878931,   71879461}, {72099371, 72099901}, {72659141, 72659711}, {72661891,   72662411}, {73123231, 73123751}, {73395451, 73395991}, {74001461,   74002021}, {74409781, 74410291}, {74664761, 74665301}, {74851981,   74852621}, {75337991, 75338651}, {75743431, 75743971}, {75868531,   75869041}, {76199411, 76200011}, {76241911, 76242451}, {76324571,   76325111}, {76605731, 76606291}, {76752251, 76752791}, {76763941,   76764491}, {77038961, 77039491}, {77358901, 77359411}, {78292801,   78293401}, {78390701, 78391211}, {79860031, 79860551}, {80064811,   80065361}, {80590721, 80591341}, {81075751, 81076291}, {81250991,   81251561}, {81604331, 81604891}, {81745591, 81746191}, {81756811,   81757391}, {82051031, 82051601}, {82638971, 82639511}, {83416121,   83416651}, {83784611, 83785201}, {83919611, 83920121}, {83967581,   83968091}, {84482311, 84482821}, {84520951, 84521461}, {85103971,   85104541}, {85409531, 85410121}, {85417261, 85417771}, {85583951,   85584601}, {85818361, 85818871}, {85945141, 85945711}, {86008561,   86009071}, {86225101, 86225791}, {86416721, 86417251}, {86539181,   86539771}, {86586931, 86587471}, {86651011, 86651611}, {86780101,   86780741}, {86883131, 86883661}, {86902741, 86903251}, {87012971,   87013571}, {87246721, 87247231}, {87491071, 87491611}, {87923741,   87924251}, {88077581, 88078121}, {88261711, 88262221}, {88492111,   88492741}, {88513291, 88513811}, {88587091, 88587641}, {88954361,   88954951}, {89042221, 89042801}, {89465291, 89465881}, {90007121,   90007661}, {90221401, 90221921}, {90392441, 90393041}, {90501011,   90501571}, {90663731, 90664391}, {91014071, 91014631}, {91058021,   91058651}, {91075181, 91075781}, {91090381, 91091041}, {91502791,   91503311}, {91637201, 91637851}, {91829321, 91829851}, {91975991,   91976501}, {92403491, 92404051}, {92502301, 92502821}, {92974171,   92974781}, {93263641, 93264341}, {93439091, 93439601}, {93528151,   93528671}, {93632831, 93633461}, {93730991, 93731501}, {93856921,   93857431}, {94641101, 94641611}, {95173391, 95173951}, {95438081,   95438671}, {95537371, 95537881}, {96114461, 96115021}, {96179821,   96180421}, {96330691, 96331241}, {96412991, 96413501}, {96506231,   96506741}, {96520841, 96521351}, {96671251, 96671801}, {97097851,   97098361}, {97579331, 97579861}, {97618511, 97619051}, {97708381,   97708951}, {97768871, 97769561}, {98202941, 98203481}, {98308591,   98309131}, {98357261, 98357911}, {98396381, 98396911}, {98593211,   98593741}, {98875591, 98876201}, {99369521, 99370031}, {99535211,   99535811}}

 把4楼的程序改成并行，输出首项与项数 Range[1,100000000,10]//ParallelCombine[Select[#,PrimeQ]&,#]&//Partition[#,2,1]&//{{6,#[[1,1]]-5}}~Join~Parallelize[{#[[1]]+5,#[[2]]-5}&/@#]~Join~{{#[[-1,-1]]+5,99999996}}&//Parallelize[{#[[1]],(#[[2]]-#[[1]])/5+1}&/@#]&//Select[#,#[[2]]>=100&]&复制代码{{7929496,107},{9775776,101},{11066926,113},{11300416,105},{11842006,111},{13167256,117},{13817566,101},{13943356,123},{15719026,101},{17904366,101},{18719796,127},{18980566,111},{19981366,105},{20494656,103},{21235116,103},{21850186,107},{22964106,101},{26318016,101},{26512536,101},{26972686,113},{27334306,107},{27449716,107},{27465966,107},{28189246,101},{30363636,103},{31278706,105},{31419816,113},{31857156,133},{34496616,115},{34610676,133},{35267866,105},{35803426,101},{36571266,115},{36657966,119},{39493066,113},{39569806,111},{40106586,119},{41242506,101},{41300106,107},{41352306,115},{41398006,105},{41614726,105},{41766426,107},{42402556,113},{43011196,101},{43421356,105},{45064366,105},{45309526,105},{45784776,101},{46895496,109},{47065536,103},{47465656,117},{48145896,103},{48783066,109},{49443456,103},{49641966,113},{50357706,109},{50384016,131},{50823586,101},{50983536,101},{51169296,109},{51443896,143},{51530356,119},{52015596,101},{52486476,109},{52946076,103},{52967176,113},{53153836,101},{53521906,129},{53729686,107},{53751096,103},{54186526,125},{54445596,103},{54581046,107},{54760476,115},{54881956,113},{54996396,113},{55294996,105},{55333636,107},{55471536,125},{55857676,123},{55978786,129},{56473516,101},{56588686,113},{56593086,113},{57021246,107},{57138186,101},{57271566,125},{57288576,103},{57444996,101},{57542536,101},{57795916,101},{57844866,121},{58076916,103},{58106376,103},{58432926,107},{58574116,107},{58935276,101},{60060256,117},{60327166,129},{61723096,117},{62183766,103},{62234896,111},{62407516,105},{63396486,127},{63921006,101},{64291576,125},{64425726,101},{65264466,115},{65554756,101},{65597806,107},{65700966,131},{65740336,101},{65995476,101},{66082006,105},{66728526,109},{67027206,101},{68447206,147},{68692896,109},{69953626,105},{70275646,131},{70400856,101},{70493796,101},{71076936,107},{71246826,107},{71878936,105},{72099376,105},{72659146,113},{72661896,103},{73123236,103},{73395456,107},{74001466,111},{74409786,101},{74664766,107},{74851986,127},{75337996,131},{75743436,107},{75868536,101},{76199416,119},{76241916,107},{76324576,107},{76605736,111},{76752256,107},{76763946,109},{77038966,105},{77358906,101},{78292806,119},{78390706,101},{79860036,103},{80064816,109},{80590726,123},{81075756,107},{81250996,113},{81604336,111},{81745596,119},{81756816,115},{82051036,113},{82638976,107},{83416126,105},{83784616,117},{83919616,101},{83967586,101},{84482316,101},{84520956,101},{85103976,113},{85409536,117},{85417266,101},{85583956,129},{85818366,101},{85945146,113},{86008566,101},{86225106,137},{86416726,105},{86539186,117},{86586936,107},{86651016,119},{86780106,127},{86883136,105},{86902746,101},{87012976,119},{87246726,101},{87491076,107},{87923746,101},{88077586,107},{88261716,101},{88492116,125},{88513296,103},{88587096,109},{88954366,117},{89042226,115},{89465296,117},{90007126,107},{90221406,103},{90392446,119},{90501016,111},{90663736,131},{91014076,111},{91058026,125},{91075186,119},{91090386,131},{91502796,103},{91637206,129},{91829326,105},{91975996,101},{92403496,111},{92502306,103},{92974176,121},{93263646,139},{93439096,101},{93528156,103},{93632836,125},{93730996,101},{93856926,101},{94641106,101},{95173396,111},{95438086,117},{95537376,101},{96114466,111},{96179826,119},{96330696,109},{96412996,101},{96506236,101},{96520846,101},{96671256,109},{97097856,101},{97579336,105},{97618516,107},{97708386,113},{97768876,137},{98202946,107},{98308596,107},{98357266,129},{98396386,105},{98593216,105},{98875596,121},{99369526,101},{99535216,119}}

楼主| 发表于 2017-5-19 15:40:55 | 显示全部楼层
 本帖最后由 TSC999 于 2017-5-19 15:55 编辑 如何编程证明：在等差数列 1，6，11，16，21，26，31，36，41，....中，存在连续 100 项均是合数。 在 mathematica 贴吧中也发了这个帖子。总结各路大神的意见，写出以下容易看懂的程序： a1 = Range[1, 10000000,   5];   (*形成一个列表，公差是 5，首项是 1、最大不超过 10000000 的等差数列 *) plist = Select[a1, PrimeQ];  (*除去其中的合数，只留下质数 *) a2 = SplitBy[a1,   PrimeQ];   (* \ 变换成二维的列表，子列表是：{合数数列1}，{第一个质数}，{合数数列2}，{第二个质数}，{合数数列3}，{第三个质数}，\ \[CenterDot]\[CenterDot]\[CenterDot]\[CenterDot]\[CenterDot]\ \[CenterDot] *) a3 = a2[[1 ;; -1 ;;     2]]; (* 筛选出其中的第 1、3、5、7、\[Ellipsis]\[Ellipsis]个子列表 *) Li = Length /@ a3 ; (* 求出上述各子列表的长度 *) Lmax = Max[Li]  (* 求出最大的长度是多少 *) n = Ordering[    Differences@plist, -1][[1]];  (* 第 n 个质数与第 n+1 个质数间的合数最多。n=? *) plist[[n ;; n + 1]]  (* 第 n 个质数与第 n+1 个质数各是什么？ *) a3[[n + 1]]  (* 最长的合数列是什么？ *) 复制代码 运行结果是： 107 {7929491,7930031} {7929496,7929501,7929506,7929511,7929516,7929521,7929526,7929531,7929536,7929541,7929546,7929551,7929556,7929561,7929566,7929571,7929576,7929581,7929586,7929591,7929596,7929601,7929606,7929611,7929616,7929621,7929626,7929631,7929636,7929641,7929646,7929651,7929656,7929661,7929666,7929671,7929676,7929681,7929686,7929691,7929696,7929701,7929706,7929711,7929716,7929721,7929726,7929731,7929736,7929741,7929746,7929751,7929756,7929761,7929766,7929771,7929776,7929781,7929786,7929791,7929796,7929801,7929806,7929811,7929816,7929821,7929826,7929831,7929836,7929841,7929846,7929851,7929856,7929861,7929866,7929871,7929876,7929881,7929886,7929891,7929896,7929901,7929906,7929911,7929916,7929921,7929926,7929931,7929936,7929941,7929946,7929951,7929956,7929961,7929966,7929971,7929976,7929981,7929986,7929991,7929996,7930001,7930006,7930011,7930016,7930021,7930026}

 又看到一个适合用穷举法回复的帖子! 补充内容 (2017-5-26 14:06): 123 补充内容 (2017-5-26 14:06): 654321

 您需要登录后才可以回帖 登录 | 欢迎注册 本版积分规则 回帖后跳转到最后一页

GMT+8, 2017-10-19 20:32 , Processed in 0.248099 second(s), 23 queries .