-
-
Save hyuki/349c4151877ca4d086b752ad8c6c332c to your computer and use it in GitHub Desktop.
N!を素因数分解したときの2の指数について
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
# N!を素因数分解したときの2の指数について | |
# cf. https://twitter.com/numachi11111/status/1315844576851050497 | |
# See also: https://oeis.org/A011371 | |
def f(n) | |
if n == 0 | |
1 | |
else | |
n * f(n-1) | |
end | |
end | |
def e(n) | |
e = 0 | |
while n % 2 == 0 | |
e += 1 | |
n /= 2 | |
end | |
e | |
end | |
1000.times do |n| | |
a = n | |
s = 0 | |
loop do | |
a = a / 2 | |
s += a | |
break if a == 0 | |
end | |
puts "N = #{n} : #{s} #{e(f(n))}" | |
end |
Author
hyuki
commented
Oct 14, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment