prog_slow.sf 959 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/ruby
  2. # a(n) is the smallest number which can be represented as the product of n distinct integers > 1 in exactly n ways.
  3. # https://oeis.org/A360590
  4. # Known terms:
  5. # 2, 12, 60, 420, 3456, 60060
  6. # New terms found:
  7. # a(7) = 155520
  8. func isok(k, n) {
  9. func f(n, target, factors, res = 1, k = 0, i = 0) {
  10. if ((res == target) && (k == n)) {
  11. return 1
  12. }
  13. if (k == n) {
  14. return 0
  15. }
  16. if (res >= target) {
  17. return 0
  18. }
  19. var count = 0
  20. for j in (i .. factors.end) {
  21. var t = res*factors[j]
  22. t <= target || break
  23. count += f(n, target, factors, t, k+1, j+1)
  24. }
  25. return count
  26. }
  27. var count = f(n, k, k.divisors.grep{ _ > 1})
  28. f = nil
  29. count == n
  30. }
  31. func a(n) {
  32. for k in (2..Inf) {
  33. if (isok(k, n)) {
  34. return k
  35. }
  36. }
  37. }
  38. for n in (2..100) {
  39. say [n, a(n)]
  40. }