primes/primes.pike

39 lines
508 B
Plaintext
Raw Normal View History

2011-03-08 07:01:27 +00:00
// 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;
}