Sophie

Sophie

distrib > Mageia > 1 > i586 > by-pkgid > d92aa75c2d384ff9f513aed09a46f703 > files > 526

parrot-doc-3.1.0-2.mga1.i586.rpm

#! perl

# Copyright (C) 2004-2006, Parrot Foundation.

use strict;
use warnings;

my $i   = 0;
my $max = 500;
my $i6  = 0;
my $i7;

while (1) {
    if ( &isprime1($i) ) {
        $i7 = $i;
        $i6++;
    }
    $i++;
    if ( $i == $max ) {
        last;
    }
}
printf( "N primes calculated to %d is %d\nlast is: %d\n", $max, $i6, $i7 );

sub isprime1 {
    my ($input) = @_;
    my $n;

    if ( $input < 1 ) {
        return 0;
    }
    $n = $input - 1;

    while ( $n > 1 ) {
        if ( $input % $n == 0 ) { return 0; }
        $n--;
    }
    return 1;
}

# Local Variables:
#   mode: cperl
#   cperl-indent-level: 4
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4: