2016年2月14日日曜日

160214(2)

Ruby


A generalization of Wolstenholme’s Theorem

http://www.indjst.org/index.php/indjst/article/view/30049/26003
で証明されているWolstenholme’s Theorem の一般化
の紹介とコードによる確認をしてみます。

定理
p を3 より大きな素数とする。
2t + 1 がp^r (ただし、r ≧ 0)で割り切れるとき、
1 / (tp + 1) + 1 / (tp + 2) + … + 1 / (tp + p - 1) 
を既約分数で表したとき、その分子は
p^(r + 2) で割り切れる。

1 / (tp + 1) + 1 / (tp + 2) + … + 1 / (tp + p - 1) 
をいちいち計算しなくても、
2t + 1 がp で何回割り切れるか計算し、2 足すことで、
分子がp で何回割り切れるかわかるなんて
素晴らしいですね。

このことを以下のコードを実行することで確認してみました。

require 'prime'

# nはprで何回割り切れるか?
def f(pr, n)
  i = 0
  while n % pr == 0
    n /= pr
    i += 1
  end
  i
end

# 3より大きな素数
ary = Prime.each(50).select{|i| i > 3}

ary.each{|pr|
  (0..10).each{|t|
    # 分子の計算
    n = (t * pr + 1..t * pr + pr - 1).inject(0){|s, i| s + 1.to_r / i}.numerator
    # 定理の確認
    p [pr, t, n, f(pr, 2 * t + 1) + 2 == f(pr, n)]
  }
}

出力結果
[5, 0, 25, true]
[5, 1, 275, true]
[5, 2, 3875, true]
[5, 3, 10675, true]
[5, 4, 2525, true]
[5, 5, 41525, true]
[5, 6, 68575, true]
[5, 7, 35125, true]
[5, 8, 153425, true]
[5, 9, 214225, true]
[5, 10, 96425, true]
[7, 0, 49, true]
[7, 1, 30233, true]
[7, 2, 80507, true]
[7, 3, 4370849, true]
[7, 4, 5138581, true]
[7, 5, 21063581, true]
[7, 6, 48615203, true]
[7, 7, 39799417, true]
[7, 8, 124084513, true]
[7, 9, 108231543, true]
[7, 10, 535682651, true]
[11, 0, 7381, true]
[11, 1, 13237037, true]
[11, 2, 14943591113, true]
[11, 3, 36058219373, true]
[11, 4, 1358241712157, true]
[11, 5, 533808324445, true]
[11, 6, 168482538014219, true]
[11, 7, 407844019407077, true]
[11, 8, 539763332026127, true]
[11, 9, 5144473601599541, true]
[11, 10, 301662435110641, true]
[13, 0, 86021, true]
[13, 1, 1309365187, true]
[13, 2, 1334776129583, true]
[13, 3, 16676563608913, true]
[13, 4, 446190089168473, true]
[13, 5, 317939048897587, true]
[13, 6, 36000709464543629, true]
[13, 7, 5223521989383751079, true]
[13, 8, 592152512114606963, true]
[13, 9, 719532314929492441, true]
[13, 10, 6062323290232007045, true]
[17, 0, 2436559, true]
[17, 1, 787843581751, true]
[17, 2, 4292065762987117, true]
[17, 3, 46433475296153597, true]
[17, 4, 153382369768544523293, true]
[17, 5, 1997106680308515314477, true]
[17, 6, 62422051952437858761253, true]
[17, 7, 42202311036813238919753, true]
[17, 8, 136832143170287811863503181, true]
[17, 9, 726009428138250274646921, true]
[17, 10, 120905999465951468044170199, true]
[19, 0, 14274301, true]
[19, 1, 183866178378767, true]
[19, 2, 49842554527356881, true]
[19, 3, 21269957997470249205673, true]
[19, 4, 1792093582640464736519, true]
[19, 5, 1158674748695060950063181, true]
[19, 6, 136354055658814123563949, true]
[19, 7, 28081422736063429265459792603, true]
[19, 8, 2777590907908768324735157, true]
[19, 9, 4628856084265352090056865101, true]
[19, 10, 45977928365823304039754856927, true]
[23, 0, 19093197, true]
[23, 1, 270570136019489093, true]
[23, 2, 1859271978023654837413, true]
[23, 3, 1267981507366819689425627, true]
[23, 4, 39633892226565623228991344263, true]
[23, 5, 233348690111492143711571311007, true]
[23, 6, 4446427002102068779244570451679, true]
[23, 7, 3606858186825884265649820937857579, true]
[23, 8, 68977989815498946352601392703291233, true]
[23, 9, 30736503361290230627709926437063427, true]
[23, 10, 151894535827610545072848562166147737, true]
[29, 0, 315404588903, true]
[29, 1, 3779770905377759487781, true]
[29, 2, 892339791671412806954383334033, true]
[29, 3, 9596994110162025596577970653431, true]
[29, 4, 8157452839992761113730059976155499, true]
[29, 5, 6586102479929809577883951173944555624181, true]
[29, 6, 35519344834440582092326012919405024820317, true]
[29, 7, 49599093979783235582528035951902771439, true]
[29, 8, 124853749898709715516786169725950174718650521, true]
[29, 9, 392262011659335265715647478959289813886285911, true]
[29, 10, 2524485685288778488846697293129561048381511074261, true]
[31, 0, 9304682830147, true]
[31, 1, 12757396882712863514861641, true]
[31, 2, 144843478288494288855966291259, true]
[31, 3, 1805283860602888843720236729411094739, true]
[31, 4, 139356629880976174922347930769792803, true]
[31, 5, 796326152895959979286598088011126893861531, true]
[31, 6, 2230170993510132571758290962073350149186067, true]
[31, 7, 1182790797365492046818367059687992365843260471, true]
[31, 8, 380214622213618378827982882153042459403783917, true]
[31, 9, 524906452437330964874697393180069385775519502719, true]
[31, 10, 1078554370934630943567910478707169916283338183507227, true]
[37, 0, 54801925434709, true]
[37, 1, 7466806567454896712611074058381, true]
[37, 2, 36056966290842823179836963717907077893, true]
[37, 3, 17745291924751855377351711267589021682153, true]
[37, 4, 129294436764210327508845965555258397892805561897, true]
[37, 5, 4574434182000861934636610067385864051257394703, true]
[37, 6, 169057353109064803401332146337597353199638131153593929, true]
[37, 7, 12448744686566921474936252337289520779748584924226965171, true]
[37, 8, 7640578660778495556096028510247353787969635313663533513, true]
[37, 9, 77587785293220233044429409059649547630264534707828733922337, true]
[37, 10, 228933974505229577428090388023622283735890308610937879869, true]
[41, 0, 2078178381193813, true]
[41, 1, 29121075303383578029137087244583, true]
[41, 2, 615911964773832693373893712282416759505609, true]
[41, 3, 1804744324074962841519267415033975460801794343, true]
[41, 4, 9662630946498638333332500915062876251085070512287, true]
[41, 5, 463175961888949749903716552284773908919737055232324139369, true]
[41, 6, 45394354577709776495010385631638874396816954097917942347, true]
[41, 7, 88424580251568964654149090872808178592578936477704106679353, true]
[41, 8, 101342730327636246140240982067604211313287608070663553813571147659, true]
[41, 9, 42241573995567145350698847533980034638749760938527714257736947, true]
[41, 10, 556792987697169414280180236521074810688270983090921708768886760059, true]
[43, 0, 12309312989335019, true]
[43, 1, 2307522219518793691664168029222327, true]
[43, 2, 17993181630775806667316212191745901713647587, true]
[43, 3, 22855378205111632655176533639499638849938395117787, true]
[43, 4, 93619353499384328458203252867833801340601571902612360013, true]
[43, 5, 1374294537997847376206100321950475385167278143821820363027, true]
[43, 6, 2410108548176137124317736813382721535401205644380642546439, true]
[43, 7, 6195372606593393094100817357982425999653406753243937639550432553, true]
[43, 8, 18443951826053234794196667471434343387918305495844645079856636273, true]
[43, 9, 1317780657818436118494010899093333458898155487421438101165979895046853, true]
[43, 10, 10020682213267422871477250416991451297546845194549243390790822394882421, true]
[47, 0, 5943339269060627227, true]
[47, 1, 2071326819474372895973371665510507041, true]
[47, 2, 10326463868890845864424384888839482379609550248799, true]
[47, 3, 225070277010552062017277192543443493810494762523856019, true]
[47, 4, 193495841560018237624005246490312136887644262029295224607777, true]
[47, 5, 26537946570772311514392593870012825855366118854300514865138372939, true]
[47, 6, 7669194219914715952342320712340555731099203160911183962267007791, true]
[47, 7, 9938361813241143018186827422493110581525356267607382532829046252226929, true]
[47, 8, 13587729561733711807519616449088173968787548452179768607474272105338843359, true]
[47, 9, 489572815970135531160461048700562976236978904137195938771304451088497117, true]
[47, 10, 122241793805265085436201574946285404109653206894177320882945247931831611828869, true]

0 件のコメント:

コメントを投稿

注: コメントを投稿できるのは、このブログのメンバーだけです。