Skip to content

Commit

Permalink
Problem 346
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbantuelle committed Oct 6, 2018
1 parent a3e8bdc commit 470c714
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 346.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'pp'

ceiling = 10**12

repunits = {}

def find_repunit(number, base)
((base**(number) - 1) / (base - 1))
end

2.upto(Math.sqrt(ceiling)) do |base|
counter = 2
loop do
repunit = find_repunit(counter, base)
break if repunit >= ceiling
if repunit-1 != base
repunits[repunit] = true
end
counter += 1
end
end

pp repunits.keys.inject(:+)+1

0 comments on commit 470c714

Please sign in to comment.