david/scripts-archive
david
/
scripts-archive
Archived
1
0
Fork 0
This repository has been archived on 2022-04-16. You can view files and clone it, but cannot push or open issues or pull requests.
scripts-archive/prime.pl

41 lines
674 B
Perl
Raw Permalink Normal View History

#!/usr/bin/env perl
# prime number calculation
# author: david@socialnerds.org
my $num = 3;
print "highest prime number: ";
chomp(my $maxnum = <STDIN>);
my $count = 2;
print "2\n3\n";
while ( $num <= $maxnum )
{
$i=3;
while ( $i <= int($num**(1/2)+1) )
{
if ( $i != 1 && $i < $num && $i%2 != 0 )
{
if ( $num % $i != 0 ) {
$probably = "true"
} else {
$probably = "false";
last;
}
}
$i += 2;
}
if ( $probably eq "true" )
{
print "$num\n";
$count++;
}
$num += 2;
}
print "prime number count: $count\n";