39 lines
508 B
Plaintext
39 lines
508 B
Plaintext
// 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;
|
|
}
|