http://headlines.yahoo.co.jp/hl?a=20120919-00000168-jij-soci

ABC予想がちまたで話題になっていますね。
まだ証明が発表されただけなので、これからその証明が精査されて数年後に認められるという所でしょうか。

そんなABC予想ですが、言ってる事自体は簡単です。
ABC予想を満たすコードを書いてみました。

===予備知識===
;abc-triple
:正の整数 a,b,c について、a + b = c かつ a, b は互いに素である三つ組み (a, b, c)
;rad(n)
:正の整数 n の、素因数の積。
:Ex. rad(504) = rad(2^3 * 3^2 * 7 = 2 * 3 * 7 = 42

===ABC予想===
任意の abc-triple は、c < rad(abc)^2 を満たす。



-----------以下コード---------------

include Math
require 'mathn'

def rad(n)
i=1
pq=n.prime_division
pq.each do |tes|
p tes[0]
i=i*tes[0]
end
return i
end 


for a in 2..1000 do
for b in a..5000 do
if a.gcd(b)==1 then
c=a+b
d=rad(a*b*c)
if d*d > c then
p a,b
else
p "miss"
end
end
end
end

----------------------------以上、コード---------------------------------


たのしいRuby 第3版
たのしいRuby 第3版
posted with amazlet at 12.09.20
高橋 征義 後藤 裕蔵
ソフトバンククリエイティブ
売り上げランキング: 4225