prog.jl 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/julia
  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. using Primes
  7. function divisor_sum(n)
  8. sigma = 1
  9. for (p,e) in factor(n)
  10. s = 1
  11. q = p
  12. for j in 1:e
  13. s += q^j
  14. end
  15. sigma *= s
  16. end
  17. return sigma
  18. end
  19. function f(n, q, limit)
  20. # ~ if (rem(n,6) == 0 || rem(n, 28) == 0 || rem(n, 496) == 0 || rem(n, 8128) == 0)
  21. # ~ return 0
  22. # ~ end
  23. count = 0
  24. p = q
  25. while true
  26. t = n*p
  27. (t >= limit) && break
  28. ds = divisor_sum(t)
  29. if (ds > 2*t)
  30. ok = true
  31. for (p,e) in factor(t)
  32. w = div(t,p)
  33. if (divisor_sum(w) >= 2*w)
  34. ok = false
  35. break
  36. end
  37. end
  38. if ok
  39. count += 1
  40. end
  41. elseif (ds < 2*t)
  42. count += f(t, p, limit)
  43. end
  44. p = nextprime(p+1)
  45. end
  46. return count
  47. end
  48. println(f(1, 2, 10^4))
  49. println(f(1, 2, 10^5))
  50. println(f(1, 2, 10^6))
  51. println(f(1, 2, 10^11))