Skip to content

Instantly share code, notes, and snippets.

@hyuki
Created May 14, 2020 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyuki/46aa7417f9e212da26b7a5d6b43dc57f to your computer and use it in GitHub Desktop.
Save hyuki/46aa7417f9e212da26b7a5d6b43dc57f to your computer and use it in GitHub Desktop.
mathquiz.rb - 約数の個数が連続して等しくなる数を探す
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
@hyuki
Copy link
Author

hyuki commented May 14, 2020

c( 1) =  1,  1 = 1
c( 2) =  2,  2 = 2^1
c( 3) =  2,  3 = 3^1
c( 4) =  3,  4 = 2^2
c( 5) =  2,  5 = 5^1
c( 6) =  4,  6 = 2^1 * 3^1
c( 7) =  2,  7 = 7^1
c( 8) =  4,  8 = 2^3
c( 9) =  3,  9 = 3^2
c(10) =  4, 10 = 2^1 * 5^1
c(11) =  2, 11 = 11^1
c(12) =  6, 12 = 2^2 * 3^1
c(13) =  2, 13 = 13^1
c(14) =  4, 14 = 2^1 * 7^1
c(15) =  4, 15 = 3^1 * 5^1
c(16) =  5, 16 = 2^4
c(17) =  2, 17 = 17^1
c(18) =  6, 18 = 2^1 * 3^2
c(19) =  2, 19 = 19^1
c(20) =  6, 20 = 2^2 * 5^1
c(21) =  4, 21 = 3^1 * 7^1
c(22) =  4, 22 = 2^1 * 11^1
c(23) =  2, 23 = 23^1
c(24) =  8, 24 = 2^3 * 3^1
c(25) =  3, 25 = 5^2
c(26) =  4, 26 = 2^1 * 13^1
c(27) =  4, 27 = 3^3
c(28) =  6, 28 = 2^2 * 7^1
c(29) =  2, 29 = 29^1
c(30) =  8, 30 = 2^1 * 3^1 * 5^1
c(31) =  2, 31 = 31^1
c(32) =  6, 32 = 2^5
c(33) =  4, 33 = 3^1 * 11^1
c(34) =  4, 34 = 2^1 * 17^1
c(35) =  4, 35 = 5^1 * 7^1
c(36) =  9, 36 = 2^2 * 3^2
c(37) =  2, 37 = 37^1
c(38) =  4, 38 = 2^1 * 19^1
c(39) =  4, 39 = 3^1 * 13^1
c(40) =  8, 40 = 2^3 * 5^1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment