You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

38 lines
508 B

// Pike version of a Prime Number Finder
// haplo@mindstab.net
int main(int argc, array(string) argv)
{
int max;
if(argc >= 2) {
max = (int)argv[1];
} else {
write("USEAGE: primes.pike [ Max Num ]");
return 0;
}
if(max < 2)
{
write("Invalid Max Num\n");
return 0;
}
for(int cnt=3;cnt<=max; cnt+=2)
{
int sq = sqrt(cnt);
int isp = 1;
for(int i = 3; i<=sq;i+=2)
{
if(cnt % i == 0)
{
isp = 0;
break;
}
}
if(isp) {
write(cnt + "\n");
}
}
return 0;
}