Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Arithmetic-Rational/Ruby/arithmetic-rational.rb
Normal file
12
Task/Arithmetic-Rational/Ruby/arithmetic-rational.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
for candidate in 2 .. 2**19
|
||||
sum = Rational(1, candidate)
|
||||
for factor in 2 .. Integer.sqrt(candidate)
|
||||
if candidate % factor == 0
|
||||
sum += Rational(1, factor) + Rational(1, candidate / factor)
|
||||
end
|
||||
end
|
||||
if sum.denominator == 1
|
||||
puts "Sum of recipr. factors of %d = %d exactly %s" %
|
||||
[candidate, sum.to_i, sum == 1 ? "perfect!" : ""]
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue