Untouchable numbers: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: changed wording in the REXX section header.) |
SqrtNegInf (talk | contribs) (Added Perl) |
||
Line 336: | Line 336: | ||
The count of untouchable numbers ≤ 1000000 is: 150232 |
The count of untouchable numbers ≤ 1000000 is: 150232 |
||
</pre> |
</pre> |
||
=={{header|Perl}}== |
|||
{{libheader|ntheory}} |
|||
<lang perl>use strict; |
|||
use warnings; |
|||
use enum qw(False True); |
|||
use ntheory qw/divisor_sum is_prime/; |
|||
sub sieve { |
|||
my($n) = @_; |
|||
my %s; |
|||
for my $k (0 .. $n+1) { |
|||
my $sum = divisor_sum($k) - $k; |
|||
$s{$sum} = True if $sum <= $n+1; |
|||
} |
|||
%s |
|||
} |
|||
my(%s,%c); |
|||
my($max, $limit, $cnt) = (2000, 1e5, 0); |
|||
%s = sieve 14 * $limit; |
|||
!is_prime($_) and $c{$_} = True for 1..$limit; |
|||
my @untouchable = (2, 5); |
|||
for ( my $n = 6; $n <= $limit; $n += 2 ) { |
|||
push @untouchable, $n if !$s{$n} and $c{$n-1} and $c{$n-3}; |
|||
} |
|||
map { $cnt++ if $_ <= $max } @untouchable; |
|||
print "Number of untouchable numbers ≤ $max : $cnt \n\n" . |
|||
(sprintf "@{['%6d' x $cnt]}", @untouchable[0..$cnt-1]) =~ s/(.{84})/$1\n/gr . "\n"; |
|||
my($p, $count) = (10, 0); |
|||
my $fmt = "%6d untouchable numbers were found ≤ %7d\n"; |
|||
for my $n (@untouchable) { |
|||
$count++; |
|||
if ($n > $p) { |
|||
printf $fmt, $count-1, $p; |
|||
printf($fmt, scalar @untouchable, $limit) and last if $limit == ($p *= 10) |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
<pre>Number of untouchable numbers ≤ 2000 : 196 |
|||
2 5 52 88 96 120 124 146 162 188 206 210 216 238 |
|||
246 248 262 268 276 288 290 292 304 306 322 324 326 336 |
|||
342 372 406 408 426 430 448 472 474 498 516 518 520 530 |
|||
540 552 556 562 576 584 612 624 626 628 658 668 670 708 |
|||
714 718 726 732 738 748 750 756 766 768 782 784 792 802 |
|||
804 818 836 848 852 872 892 894 896 898 902 926 934 936 |
|||
964 966 976 982 996 1002 1028 1044 1046 1060 1068 1074 1078 1080 |
|||
1102 1116 1128 1134 1146 1148 1150 1160 1162 1168 1180 1186 1192 1200 |
|||
1212 1222 1236 1246 1248 1254 1256 1258 1266 1272 1288 1296 1312 1314 |
|||
1316 1318 1326 1332 1342 1346 1348 1360 1380 1388 1398 1404 1406 1418 |
|||
1420 1422 1438 1476 1506 1508 1510 1522 1528 1538 1542 1566 1578 1588 |
|||
1596 1632 1642 1650 1680 1682 1692 1716 1718 1728 1732 1746 1758 1766 |
|||
1774 1776 1806 1816 1820 1822 1830 1838 1840 1842 1844 1852 1860 1866 |
|||
1884 1888 1894 1896 1920 1922 1944 1956 1958 1960 1962 1972 1986 1992 |
|||
2 untouchable numbers were found ≤ 10 |
|||
5 untouchable numbers were found ≤ 100 |
|||
89 untouchable numbers were found ≤ 1000 |
|||
1212 untouchable numbers were found ≤ 10000 |
|||
13863 untouchable numbers were found ≤ 100000</pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |