generate.sf 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/ruby
  2. # Number of primitive abundant numbers (A071395) < 10^n.
  3. # https://oeis.org/A306986
  4. # Known terms:
  5. # 0, 3, 14, 98, 441, 1734, 8667, 41653, 213087, 1123424
  6. #var PERFECT = [6, 28, 496, 8128, 33550336, 8589869056, 137438691328, 2305843008139952128, 2658455991569831744654692615953842176].grep{ _ <= 1e10 }
  7. func f(n, q, limit) {
  8. #PERFECT.none { n.is_div(_) } || return false
  9. var count = 0
  10. for(var p = q; true; p.next_prime!) {
  11. var t = n*p
  12. break if (t >= limit)
  13. # This includes terms with perfect divisors
  14. if (t.is_primitive_abundant) {
  15. count += 1
  16. }
  17. else {
  18. count += f(t, p, limit)
  19. }
  20. }
  21. return count
  22. }
  23. say f(1, 2, 1e4)
  24. __END__
  25. # PARI/GP programs
  26. # Generate terms
  27. prim_abundant(n, q, limit) = my(list=List()); forprime(p=q, oo, my(t = n*p); if(t >= limit, break); if(sigma(t) > 2*t, my(F=factor(t)[, 1], ok=1); for(i=1, #F, if(sigma(t\F[i], -1) > 2, ok=0; break)); if(ok, listput(list, t)), list = concat(list, prim_abundant(n*p, p, limit)))); list;
  28. # Count only
  29. prim_abundant(limit, n=1, q=2) = my(count=0); forprime(p=q, oo, my(t = n*p); if(t >= limit, break); if(sigma(t) > 2*t, my(F=factor(t)[, 1], ok=1); for(i=1, #F, if(sigma(t\F[i], -1) >= 2, ok=0; break)); if(ok, count += 1), count += prim_abundant(limit, n*p, p))); count;
  30. a(n) = prim_abundant(10^n);