Created
August 12, 2012 08:40
-
-
Save yuuki/3330697 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def d(n) | |
| t = (2..Math.sqrt(n).floor).select{|i| n % i == 0} | |
| ([1] + t + t.map{|i| n/i}).inject(:+) | |
| end | |
| amicable_num = (2...10000).select do |a| | |
| b = d(a) | |
| a == d(b) and a != b | |
| end | |
| puts amicable_num.inject(:+) | |
| # 31626 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment