is_infinitary_divisor.sf 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/ruby
  2. # Check if a given divisors d of n, is an infinitary divisors of n.
  3. # See also:
  4. # https://oeis.org/A049417
  5. # https://oeis.org/A077609
  6. func is_infinitary_divisor(d, n, P = n.prime_divisors) {
  7. P.each {|p|
  8. var n2 = n.valuation(p)
  9. var d2 = d.valuation(p)
  10. (n2 & d2) == d2 || return false
  11. }
  12. return true
  13. }
  14. func infinitary_divisors(n) {
  15. var D = n.divisors
  16. var P = D.grep { .is_prime }
  17. D.grep {|d| is_infinitary_divisor(d, n, P) }
  18. }
  19. for n in (1..20) {
  20. say "i-divisors of #{n} = #{infinitary_divisors(n)}"
  21. assert_eq(infinitary_divisors(n).len, n.isigma0)
  22. assert_eq(infinitary_divisors(n).sum, n.isigma)
  23. }
  24. __END__
  25. i-divisors of 1 = [1]
  26. i-divisors of 2 = [1, 2]
  27. i-divisors of 3 = [1, 3]
  28. i-divisors of 4 = [1, 4]
  29. i-divisors of 5 = [1, 5]
  30. i-divisors of 6 = [1, 2, 3, 6]
  31. i-divisors of 7 = [1, 7]
  32. i-divisors of 8 = [1, 2, 4, 8]
  33. i-divisors of 9 = [1, 9]
  34. i-divisors of 10 = [1, 2, 5, 10]
  35. i-divisors of 11 = [1, 11]
  36. i-divisors of 12 = [1, 3, 4, 12]
  37. i-divisors of 13 = [1, 13]
  38. i-divisors of 14 = [1, 2, 7, 14]
  39. i-divisors of 15 = [1, 3, 5, 15]
  40. i-divisors of 16 = [1, 16]
  41. i-divisors of 17 = [1, 17]
  42. i-divisors of 18 = [1, 2, 9, 18]
  43. i-divisors of 19 = [1, 19]
  44. i-divisors of 20 = [1, 4, 5, 20]