Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'prime'
- def factors_of(number)
- primes, powers = number.prime_division.transpose
- exponents = powers.map{|i| (0..i).to_a}
- divisors = exponents.shift.product(*exponents).map do |powers|
- primes.zip(powers).map{|prime, power| prime ** power}.inject(:*)
- end
- divisors.sort.map{|div| [div, number / div]}
- end
- def sigma1(nmax)
- arr = []
- if( nmax>1 )
- ar0 = factors_of(nmax)
- ar0.each do |x,y|
- arr.push(x)
- end
- arr.inject(0) do |sum,x|
- sum + x
- end
- else
- 0
- end
- end
- def equal_sigma1(nmax)
- limit = nmax
- arr = {}
- sum = 0
- while (nmax>1)
- rev_nmax = nmax.to_s.reverse
- if nmax.to_s != rev_nmax && ( nmax<=limit || rev_nmax.to_i<=limit ) && sigma1( nmax )==sigma1( rev_nmax.to_i )
- if nmax<=limit
- arr[nmax] = nmax
- end
- if rev_nmax.to_i<=limit
- arr[rev_nmax.to_i] = rev_nmax.to_i
- end
- end
- nmax -= 1
- end
- arr.each do |var,v|
- sum += var.to_i
- end
- #sum = 36784
- sum
- end
Add Comment
Please, Sign In to add comment