Consecutive Congruent Primes

This page lists the first run of r consecutive primes with the same value modulo n:
n = 4, 6, 7, 8, 9, 10, 11, 12.

If n is odd then (mod 2n) gives the same runs as (mod n) for primes above n.

As discussed in replies to http://groups.yahoo.com/group/primenumbers/message/17962, 3 consecutive small primes don't have independent values modulo 3. The value changes significantly more than half the time. This skew is amplified for many consecutive primes, and it's also present for modulo 4.

The below tables show the starting prime in the first run of exactly r primes ("exactly" means it isn't part of a longer run).
The tables for n = 4 and n = 6 also show the first run of alternating residues starting with each of the 2 possibilities.
Congruent runs were searched to 10^13, alternating runs only to 10^12. 0 means no occurrence below that.

Note that alternating long runs come much earlier, and there are much longer alternating runs despite the lower search limit.
This 21-run especially stands out:
forprime (p=809, 941, print1(p%6" "))
5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5
Modulo 4
Run    1 (mod 4)      3 (mod 4)  1,3,..(mod 4)  3,1,..(mod 4)
---    ---------      ---------  -------------  -------------
1              5              3             97            211
2             13              7             17             11
3             89            739            773              3
4            389            199            281             23
5           2593            883            317             47
6          12401          13127            409            167
7          77069            463           8009            131
8         262897          36551           6229           2011
9          11593          39607            233          17903
10        373649         183091          23633          25771
11        766261        4468903         228601          34499
12       3358169        6419299           1013          65867
13      12204889         241603           9341          49523
14      18256561       11739307         325217          90659
15      23048897        9177431            521         115979
16      12270077       95949311          51749         819583
17     297387757      105639091         505049        1865719
18     310523021      341118307        3773941        1391087
19     297779117     1800380579        5414081        2264839
20    3670889597      727334879        2556713       25123303
21    5344989829     9449915743       17123893      142003427
22    1481666377     1786054147        2569529       20855239
23    2572421893    22964264027       15090641       38907623
24    1113443017    54870713243       49008077       18246451
25  121117598053    79263248027      855234581        6160043
26   84676452781   454648144571     1756321181     1557431471
27  790457451349   722204126767       43679609      152226383
28 3498519134533  1749300591127      198572029     1450303451
29  689101181569  5070807638111      701575297     7152451231
30 3289884073409  8858854801319     7197633617     5552898499
31             0  6425403612031    12661191689     6639843979
32             0   113391385603   103272232741    61233611783
33 3278744415797              0   170951814773     9005520203
34             0              0   626798928989    99052377023
35             0              0   521204950769   380268915347
36             0              0   148638667361   946617613831
37             0              0   438921167921              0
38             0              0              0   929291719511

Jim Fougeron found some of the long congruent runs in 
http://www.primepuzzles.net/puzzles/puzz_256.htm
The 32-run at 113391385603 was the first congruent run above 26.

Modulo 6
Run    1 (mod 6)      5 (mod 6)  1,5,..(mod 6)  5,1,..(mod 6)
---    ---------      ---------  -------------  -------------
1              7              5            157             53
2             31             23             79             29
3            151             47             67            239
4           3049            251             37            137
5           7351           1889           1039            449
6           1741           7793            757            179
7          19471          43451           5569              5
8         118801         243161           2719            389
9         498259         726893            277             89
10        148531         759821          15667           2213
11        406951        2280857          11149         128903
12       2513803        1820111          10369          31469
13       2339041       10141499           8527           6761
14      89089369       40727657         113341         729269
15      51662593       19725473         780823          80447
16      73451737      136209239         151909        1303931
17     232301497      744771077          43777        1485353
18     450988159      400414121        2964553        7406639
19    1558562197     1057859471        4397803        1457333
20    2506152301      489144599         175573        1295219
21    1444257673    13160911739        6510079            809
22   28265029657      766319189        3954889       87902999
23   24061965043    38451670931      153544819      121930481
24   87996684091   119618704427       96050953      153576737
25   43553959717    21549657539       15186319      590121509
26  502429570231   141116164769      296080717      858510551
27 1820249525317   140432294381       98380549     3354061163
28 1892672756731   437339303279      131125681       77011289
29 4236406530997  1871100711071     2720227693    11048169689
30 2155866992887  3258583681877    52881047647     5696814287
31 1552841185921  5611314737339    25183752283     1572386903
32             0 24738041398529     4136299357    27799525007
33             0              0    95832732277      288413159
34             0              0   191765532499    62585146739
35             0 41173225034771   114058236679   348989218973
36             0              0   290614512109   405541876307
37             0              0              0              0
38             0              0   143014298809              0

Modulo 7
Run    1 (mod 7)      2 (mod 7)      3 (mod 7)      4 (mod 7)      5 (mod 7)      6 (mod 7)
---    ---------      ---------      ---------      ---------      ---------      ---------
1             29              2              3             11              5             13
2            113            317            773           3833           2357            293
3          37997          27197           5939          13339         106979          53731
4         575261         158867         341687         621527         637201         709547
5       12089267         894287        2617429        6760009        2809889        2993171
6       16292389       12883313        6996307       99641903       50503213      361718083
7        9984437       28648489     1232089337       49297819      345638333      279470351
8     1523792929     2428644899     4130894953      887048411     8295635297     3194228239
9    72027611573    62425749731    84834279799   137875952281    45914196389    19417691299
10  469100516641   288991234079   595178892367   208220255429    73838834753   314183482199
11 7384176068963  6201133988723    49722411511  3400274815627  3313036899877  2955453870529
12             0              0  2016473757721              0              0              0

Modulo 8
Run    1 (mod 8)      3 (mod 8)      5 (mod 8)      7 (mod 8)
---    ---------      ---------      ---------      ---------
1             17              3              5              7
2             89            491            389            359
3           2593           2243           2213           1823
4          20809          42299          45013          79063
5         208393         274123          73133         272863
6        2663897        4701443        1319861         989647
7        7336457        4310083        3250469       12955687
8      128910097        9065867       29662253       10604519
9       42453937      547580443       35677501     1062619847
10    1506473153     1885434347      101341613      309202951
11   24771906961     8674616939    13576124357     1383423311
12  123737745289    11312238283    12664911341    21120585463
13  201975758113    19201563659   124809839701   848540003159
14  152368449001   619849118491   132932904029   714231497663
15 4990160038937  4056100954547  1181960064853   534956098463
16             0              0              0   925195153703

Modulo 9
Run    1 (mod 9)      2 (mod 9)      4 (mod 9)      5 (mod 9)      7 (mod 9)      8 (mod 9)
---    ---------      ---------      ---------      ---------      ---------      ---------
1             19              2             13              5              7             17
2            523           5483           1381           1913           1069           1259
3          15823          25373          78241          20183          56131          22193
4         655453         182243         107509          74453          76543         132893
5       19256491        8606603        5321191       12859961       32820883       24143993
6       24084793        5379113       89121073      131695853       39874273      166539707
7      303392377     1734847733      561940843       18410243      399481171      285688421
8     3408167431    12196390601     1324001281     1248749069      716230591      881160173
9    17875882441    17619405959    34344033133   147779659553    10930792111    41142907853
10  179445819277   213529133423  1209605011789   435916100219   168445529647   283892437529
11 1563518842687  2732797330031  3877795268653  2113591441739  1379581580653  2133943155503
12             0              0              0              0  4016465016163              0

Modulo 10
Run   1 (mod 10)     3 (mod 10)     7 (mod 10)     9 (mod 10)
---   ----------     ----------     ----------     ----------
1             11              3              7             19
2            181            283            337            139
3           4831           6793           1627           3089
4          22501          22963          57427          18839
5         216401         752023         192637         123229
6        2229971        2707163         776257        2134519
7        3873011       58339093       15328637       12130109
8       91335901       44923183       70275277       23884639
9       36539311      961129823      244650317      363289219
10     196943081     1147752443     4075366567     9568590299
11   14293856441     6879806623      452942827    24037796539
12  363373386721   131145172583    73712513057   130426565719
13  381206903941   177746482483   319931193737   405033487139
14  154351758091   795537219143  2618698284817  3553144754209
15             0  4028596340953              0  4010803176619
16             0  6987191424553              0              0

Modulo 11
Run   1 (mod 11)     2 (mod 11)     3 (mod 11)     4 (mod 11)     5 (mod 11)
---   ----------     ----------     ----------     ----------     ----------
1             23              2              3             37              5
2           2311          10111           6427           1951           2557
3         452453        1066067        1503967        1023653         259033
4        5442361        2078221       52636411       11488261        6402181
5     2880836267     1322239547      145255861      396185431      236298529
6     4436243989     9429065747    12933776221    16535952019    13930111453
7    56675840497    55612826029    44742288583   195520526821    85272006649
8  1901256504247  4524017321287  4995900592103  9570670849997  1825518960479
9              0              0              0              0  3917068823123

Run   6 (mod 11)     7 (mod 11)     8 (mod 11)     9 (mod 11)    10 (mod 11)
---   ----------     ----------     ----------     ----------    -----------
1             17              7             19             31             43
2           3229           1129          15683           8017           3739
3         674603         444187         376307         466651         846757
4       13906261       24780961        1736281       12202507       16601881
5      222022037      258318287      140369941      222838097      267746797
6    11087576671    10550203099     1180181747     9725254999     6285546277
7    90331649557    81795872209   272006616241   288595010317    94043028529
8              0   492755092111  1204047928861  2217422600941  1328517155569
9              0              0  4682876776597              0              0

Modulo 12
The same value mod 12 means the same value both mod 4 and mod 6.

Run   1 (mod 12)     5 (mod 12)     7 (mod 12)    11 (mod 12)
---   ----------     ----------     ----------    -----------
1             13              5              7             11
2            661            509            619            467
3           8317           4397            199           1499
4          12829          42509          32443          16763
5         586153         657197         407023         260339
6        1081417         647417         180799        2003387
7       10793941        1248869        4338787        7722419
8        7790917       13175609       84885631       20221283
9      682829881      234946997      472798219      927161471
10    1921572157     1039154933     1786054267     4284484931
11     370861009     7114719473     6024282871     7355362139
12    5637496849   183420597029    64791932287    84805717127
13  289391626057    32021552837   592175010019   478527373859
14  469257742237  1237381737257  6265824724519  2046207697631
15  628337233501  5760582040217  7816088451907  7302359785151
16             0  9194779588901              0              0
17             0  2904797643617              0              0
OEIS shows that many of the above mod 12 values were first computed by Giovanni Resta.
In http://www.primepuzzles.net/puzzles/puzz_016.htm he also computed mod 10 values, i.e. same ending digit in decimal. My computation agrees.
In http://www.primepuzzles.net/puzzles/puzz_572.htm he reported run 32 of 5 (mod 6) at 24738041398529, and run 35 at 41173225034771.

By Jens Kruse Andersen. home
Last updated 6 February 2011.