Created
May 14, 2020 00:07
-
-
Save hyuki/46aa7417f9e212da26b7a5d6b43dc57f to your computer and use it in GitHub Desktop.
mathquiz.rb - 約数の個数が連続して等しくなる数を探す
This file contains 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
require 'mathn' | |
def w(k) | |
a = [] | |
k.prime_division.each do |pn| | |
a << "#{pn[0]}^#{pn[1]}" | |
end | |
if a.size > 0 | |
a.join(' * ') | |
else | |
'1' | |
end | |
end | |
def c(k) | |
n = 1 | |
k.prime_division.each do |pn| | |
n *= pn[1] + 1 | |
end | |
n | |
end | |
40.times do |i| | |
k = i + 1 | |
printf("c(%2d) = %2d, %2d = %s\n", k, c(k), k, w(k)) | |
end | |
# cf. https://twitter.com/ysmemoirs/status/1260555508722700289 | |
# cf. https://twitter.com/hyuki/status/1260719156447506432 | |
# cf. https://www.sakalab.org/prog-ruby/ruby-man-html-20080121/mathn.html |
Author
hyuki
commented
May 14, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment