nth_n-powerful.sf 336 B

1234567891011121314151617181920212223
  1. #!/usr/bin/ruby
  2. # Generate the n-th n-powerful number.
  3. func nth_powerful(n,k=2) {
  4. var min = 0
  5. var max = 1
  6. while (powerful_count(max, k) < n) {
  7. min = max+1
  8. max *= 2
  9. }
  10. bsearch_min(min, max, {|v|
  11. powerful_count(v,k) <=> n
  12. })
  13. }
  14. for n in (1..100) {
  15. say (n, " ", nth_powerful(n,n))
  16. }