1~9を左または右に付け加える操作で得られる数字がずっと素数
以下のコードで求めてみた。
require 'prime'
def A(n)
ary = [2, 3, 5, 7]
p [ary.size, ary]
(n - 1).times{|i|
ary1 = []
ary.each{|a|
(1..9).each{|d|
j = d * 10 ** (i + 1) + a
ary1 << j if j.prime?
j = a * 10 + d
ary1 << j if j.prime?
}
}
ary = ary1.uniq
p [ary.size, ary]
}
end
A(5)
出力結果
[4, [2, 3, 5, 7]]
[16, [23, 29, 13, 31, 43, 53, 73, 37, 83, 59, 17, 71, 47, 67, 97, 79]]
[70, [223, 233, 523, 823, 239, 229, 293, 829, 929, 113, 131, 313, 613, 137, 139, 311, 331, 431, 631, 317, 433, 443, 643, 743, 439, 353, 653, 853, 953, 173, 373, 733, 673, 773, 739, 337, 937, 379, 283, 383, 683, 883, 983, 839, 359, 593, 659, 859, 599, 617, 179, 271, 571, 971, 719, 347, 547, 647, 947, 479, 167, 367, 467, 677, 967, 197, 397, 797, 977, 997]]
[243, [1223, 2237, 2239, 2333, 5233, 8233, 2339, 1523, 5231, 4523, 7523, 5237, 1823, 8231, 3823, 6823, 7823, 8237, 2393, 9239, 2399, 1229, 3229, 2293, 4229, 6229, 7229, 2297, 8293, 9293, 2939, 8291, 6829, 7829, 8297, 9829, 3929, 8929, 9929, 2113, 5113, 6113, 2131, 6131, 1319, 3313, 3137, 1613, 3613, 6133, 9613, 2137, 1373, 9137, 4139, 1399, 2311, 6311, 8311, 9311, 3119, 3331, 7331, 3319, 5431, 8431, 9431, 3631, 6317, 9631, 8317, 1433, 3433, 7433, 4337, 9433, 4339, 5443, 8443, 3643, 4643, 7643, 9643, 5743, 9743, 1439, 4391, 4397, 9439, 3533, 6353, 8353, 3539, 5653, 6653, 3853, 7853, 8537, 8539, 2953, 9533, 5953, 9539, 1733, 6173, 9173, 3373, 3733, 4373, 6373, 3739, 7333, 4733, 6733, 9733, 3673, 4673, 6673, 7673, 6737, 7393, 9739, 3371, 6337, 9337, 9371, 4937, 7937, 9377, 3793, 6379, 3797, 1283, 2833, 4283, 7283, 2837, 9283, 2383, 3833, 2683, 6833, 5683, 8831, 6883, 7883, 8837, 9883, 8839, 9833, 6983, 9839, 5839, 3359, 3593, 6359, 2593, 5939, 2659, 3659, 5659, 6659, 6599, 8597, 9859, 8599, 2617, 3617, 2179, 5179, 8179, 2711, 3271, 2713, 4271, 6271, 2719, 1571, 5711, 3571, 6571, 5717, 2971, 6971, 8971, 9719, 3719, 7193, 6719, 8719, 2347, 3347, 5347, 5471, 3547, 4547, 6547, 7547, 5477, 9547, 5479, 2647, 6473, 5647, 8647, 3947, 9473, 6947, 9479, 4793, 4799, 3167, 5167, 8167, 1367, 3671, 6367, 3677, 2467, 3467, 8467, 9467, 4679, 2677, 8677, 9677, 6779, 3967, 4967, 6967, 9967, 9679, 1973, 5197, 6197, 1979, 6397, 9397, 2797, 6977, 1997, 9973, 6997]]
[638, [31223, 61223, 81223, 12239, 32237, 52237, 82237, 92237, 22391, 42239, 22397, 23333, 92333, 23339, 15233, 45233, 95233, 18233, 78233, 82339, 23399, 21523, 52313, 95231, 84523, 67523, 87523, 97523, 75239, 25237, 85237, 52379, 91823, 38231, 58231, 63823, 73823, 38237, 38239, 16823, 96823, 68239, 27823, 82373, 58237, 88237, 82393, 39239, 59239, 69239, 92399, 23993, 51229, 91229, 13229, 32297, 93229, 32299, 42293, 22937, 24229, 84229, 94229, 42299, 16229, 36229, 46229, 62297, 62299, 22973, 92297, 82939, 39293, 89293, 32939, 62939, 29399, 82913, 16829, 46829, 76829, 57829, 67829, 97829, 28297, 98297, 39829, 69829, 79829, 99829, 98299, 23929, 63929, 78929, 98929, 39929, 59929, 69929, 99929, 12113, 21139, 51131, 51133, 51137, 26113, 56113, 86113, 21313, 42131, 62131, 21317, 21319, 36131, 56131, 86131, 31319, 13313, 43313, 63313, 83137, 31379, 21613, 51613, 61613, 16139, 13613, 33613, 43613, 73613, 36137, 61331, 61333, 46133, 61339, 49613, 79613, 96137, 62137, 21377, 21379, 81373, 91373, 29137, 89137, 99137, 54139, 41399, 11399, 71399, 13997, 13999, 62311, 23117, 92311, 63113, 56311, 86311, 18311, 48311, 68311, 78311, 83117, 29311, 93113, 33119, 31193, 13331, 33311, 33331, 43331, 63331, 73331, 33317, 57331, 33191, 43319, 93319, 33199, 54311, 75431, 54319, 38431, 84313, 84317, 84319, 69431, 89431, 99431, 36313, 36319, 26317, 63179, 39631, 79631, 38317, 78317, 83177, 98317, 21433, 91433, 73433, 34337, 67433, 87433, 24337, 19433, 94331, 49433, 79433, 43391, 43397, 43399, 15443, 54437, 95443, 18443, 84431, 68443, 84437, 98443, 36433, 73643, 46439, 37643, 87643, 96431, 99643, 75743, 59743, 51439, 81439, 24391, 43913, 84391, 43973, 94397, 39439, 69439, 99439, 94399, 33533, 63533, 35339, 36353, 86353, 96353, 18353, 48353, 83537, 23539, 35393, 56531, 56533, 75653, 36653, 66533, 66653, 43853, 63853, 37853, 57853, 67853, 87853, 78539, 28537, 58537, 18539, 48539, 68539, 12953, 29531, 42953, 72953, 29537, 89533, 95339, 45953, 59539, 95393, 69539, 17333, 91733, 66173, 29173, 99173, 33739, 37337, 37339, 24373, 64373, 36373, 66373, 63737, 37397, 93739, 24733, 47339, 66733, 76733, 67339, 39733, 99733, 73673, 36739, 34673, 54673, 84673, 16673, 76673, 66739, 27673, 97673, 26737, 56737, 96737, 17393, 73939, 19739, 49739, 69739, 97397, 23371, 33713, 93371, 46337, 66337, 63377, 96337, 69337, 79337, 93377, 39371, 69371, 89371, 99371, 93719, 64937, 79379, 59377, 99377, 43793, 63793, 76379, 63799, 33797, 21283, 51283, 61283, 81283, 91283, 32833, 34283, 64283, 42839, 27283, 57283, 97283, 52837, 82837, 92831, 79283, 23831, 23833, 62383, 72383, 92383, 38333, 83833, 26833, 42683, 62683, 92683, 26839, 36833, 15683, 75683, 58831, 16883, 66883, 76883, 27883, 67883, 97883, 78839, 28837, 98837, 88379, 39883, 18839, 38839, 88397, 29833, 59833, 69833, 89833, 99833, 56983, 39839, 89839, 99839, 58391, 35839, 58393, 65839, 33359, 53359, 33599, 23593, 35933, 53593, 56359, 66359, 63599, 25931, 25933, 92593, 25939, 59393, 59399, 12659, 26591, 62659, 26597, 63659, 36599, 56591, 45659, 75659, 56597, 56599, 66593, 56659, 65993, 86599, 28597, 68597, 98597, 69859, 99859, 85991, 85999, 26171, 62617, 72617, 26177, 33617, 53617, 63617, 83617, 42179, 92179, 21799, 45179, 65179, 51797, 48179, 78179, 98179, 81799, 52711, 32713, 43271, 32717, 32719, 12713, 64271, 42719, 46271, 66271, 27191, 72719, 27197, 91571, 55711, 85711, 57119, 73571, 36571, 65713, 66571, 65717, 65719, 25717, 57173, 55717, 85717, 95717, 57179, 32971, 62971, 29717, 38971, 39719, 99719, 23719, 53719, 63719, 83719, 37199, 71933, 57193, 86719, 18719, 12347, 23473, 62347, 92347, 33347, 63347, 33479, 75347, 53479, 25471, 54713, 95471, 33547, 73547, 24547, 54547, 94547, 16547, 65479, 37547, 67547, 87547, 97547, 75479, 54773, 54779, 49547, 95479, 54799, 12647, 32647, 72647, 92647, 26479, 36473, 56473, 15647, 65647, 56477, 56479, 48647, 86477, 29473, 59473, 69473, 26947, 36947, 66947, 94793, 24793, 47933, 64793, 84793, 47939, 24799, 23167, 51673, 65167, 75167, 51679, 81671, 38167, 78167, 81677, 91367, 13679, 23671, 36713, 63671, 76367, 23677, 36779, 24671, 32467, 42467, 62467, 72467, 24677, 92467, 63467, 34679, 78467, 98467, 59467, 69467, 54679, 64679, 42677, 26777, 86771, 38677, 48677, 69677, 96779, 56779, 13967, 39671, 33967, 93967, 39679, 24967, 84967, 79967, 99679, 96797, 96799, 31973, 51973, 81973, 51971, 45197, 51977, 56197, 86197, 61979, 19793, 63977, 93971, 39397, 79397, 99397, 93979, 32797, 42797, 72797, 66977, 69779, 21997, 19973, 91997, 19979, 79973, 36997, 46997, 96997]]
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。