Sequence: nth number with exactly n divisors: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: edit debris cleanup) |
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Expand a bit, add an online link) |
||
Line 17: | Line 17: | ||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
{{works with|Rakudo|2019.03}} |
{{works with|Rakudo|2019.03}} |
||
[https://tio.run/##dVLbTsJAEH3nKw4IpgW6ATQY2QAao4kvmsijEFPoVpr05nZr2hh@yk/wx@p0CwUf3JfuzJwzc/ZMYyH9cVEk6RqO92ltojRUMJaZia8G6EihUhliBM9FxrzEiqUXCK5rPde3CTwEY1RLPqRirh9F0mSBHU9gzbB09m3Kk4a@SBJk6IDSCHIsc0wppsFwOCiYUmU@p1uzCSPvwzGx0/xdg74NorR9L/AU0UYDXmVutKKEUu9SxNS4VoldH0PGuryxx7xW7BXHGSqE2grYUto5w@Lu6YU6xqlC68GTiTrMUkIGCSIXz/ePi8nt4OriejhucY00qH8FM9k2j4U0JqO1rTbbowftcO@BQbcZLmGHDiVrlSa9WNdFFpcQC8M@asE6XplkiMY40YmhpR0evXvA/6ZIsK0iSRWidzq0PPK0VNo1tbH6Vunr/nwfyTWTueX7JyejyhOKTB2WSI1pWey8/mf4v9BerxRZavmLab/VYb1jXhS/ Try it online!] |
|||
<lang perl6>sub div-count (\x) { |
<lang perl6>sub div-count (\x) { |
||
Line 25: | Line 27: | ||
} |
} |
||
my $limit = |
my $limit = 20; |
||
my @primes = grep { .is-prime }, 1..*; |
my @primes = grep { .is-prime }, 1..*; |
||
Line 45: | Line 47: | ||
};</lang> |
};</lang> |
||
<pre>First |
<pre>First 20 terms of OEIS:A073916 |
||
1 3 25 14 14641 44 24137569 70 1089 405 819628286980801 160 22563490300366186081 2752 9801</pre> |
1 3 25 14 14641 44 24137569 70 1089 405 819628286980801 160 22563490300366186081 2752 9801 462 21559177407076402401757871041 1044 740195513856780056217081017732809 1520</pre> |
Revision as of 18:06, 11 April 2019
Sequence: nth number with exactly n divisors is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Calculate the sequence where each term an is the nth that has n divisors.
- Task
Show here, on this page, at least the first 15 terms of the sequence.
- See also
- Related tasks
Perl 6
<lang perl6>sub div-count (\x) {
return 2 if x.is-prime; +flat (1 .. x.sqrt.floor).map: -> \d { unless x % d { my \y = x div d; y == d ?? y !! (y, d) } }
}
my $limit = 20;
my @primes = grep { .is-prime }, 1..*; @primes[$limit]; # prime the array. SCNR
put "First $limit terms of OEIS:A073916"; put (1..$limit).hyper(:2batch).map: -> $n {
($n > 4 and $n.is-prime) ?? exp($n - 1, @primes[$n - 1]) !! do { my $i = 0; my $iterator = $n %% 2 ?? (1..*) !! (1..*).map: *²; $iterator.first: { next unless $n == .&div-count; next unless ++$i == $n; $_ } }
};</lang>
First 20 terms of OEIS:A073916 1 3 25 14 14641 44 24137569 70 1089 405 819628286980801 160 22563490300366186081 2752 9801 462 21559177407076402401757871041 1044 740195513856780056217081017732809 1520