prog.sf 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/ruby
  2. # a(n) is the least number such that the concatenation of all the previous terms with it is squarefree and has n prime factors. a(0)=0.
  3. # https://oeis.org/A309234
  4. # Known terms:
  5. # 0, 2, 1, 10, 29, 5, 154, 66, 1005, 158, 18634, 8190
  6. # Incorrect terms:
  7. # 285510, 196790, 847630
  8. # Corrected terms:
  9. # a(12) = 113022
  10. # a(13) = 62010
  11. # a(14) = 102310
  12. # a(15) = 5313758
  13. # a(16) = 15617985
  14. # a(17) = 510510
  15. # Lower-bounds:
  16. # a(18) > 51844464
  17. # PARI/GP program:
  18. # a(n) = if(n==0, return(0)); my(prefix=vector(n-1, k, Str(a(k)))); for(k=1, oo, my(t=eval(concat(concat(prefix, [Str(k)])))); if(issquarefree(t) && bigomega(t) == n, return(k))); \\ ~~~~
  19. # PARI/GP program (v2):
  20. # my(n=1,L=[]); print1("0, "); while(1, for(k=1, oo, my(t=eval(concat(concat(L, [Str(k)])))); if(issquarefree(t) && bigomega(t) == n, print1(k, ", "); L=concat(L, [Str(k)]); n += 1; break))); \\ ~~~~
  21. func prefix(n) {
  22. var known = [0, 2, 1, 10, 29, 5, 154, 66, 1005, 158, 18634, 8190, 113022, 62010, 102310, 5313758, 15617985, 510510]
  23. if (n <= known.end) {
  24. return known[n]
  25. }
  26. die "Too large: n = #{n}"
  27. }
  28. func a(n, from=0) {
  29. return 0 if (n == 0)
  30. var v = (^n -> map(prefix).join)
  31. for k in (from..Inf) {
  32. say "Checking: #{k}"
  33. if (Num(v + k).is_squarefree_almost_prime(n)) {
  34. say "Found: a(#{n}) = #{k}"
  35. return k
  36. }
  37. }
  38. }
  39. say a(18, 51844464)