From:                   [EMAIL PROTECTED]
> if you are in school project probably the prof will preffer you to do
> it without using the div or mod operation. Probably he is meening the
> 'Erosthosthenes algorithm'.
> 
> Marcos

Please DO NOT TOP POST!

And I don't think the prof is "meening" anything. He might "mean" 
something though.

> -----Original Message-----
> From: Joel [mailto:[EMAIL PROTECTED]
> Sent: Thursday, February 26, 2004 1:41 PM
> To: perl
> Subject: Re: Is there an etc. command in perl?
> 
> Sorry, I should have said. I'm writing a program to find prime
> numbers, and what I want it to do is go from 0 to 200 and divide each
> number by all other numbers. So I want say, 50 to be divided by 1 to
> 50, but to stop when it finds a modulus. If it were a prime number, it
> would be divided by everything between 1 and itself, and no modulus
> would be found. Any suggestions?

1. There is no point dividing by 1. 

2. It is enough to test the divisibility by numbers only up to 
sqrt(x). Proof is left to the reader as an easy homework.

3. You want to read 
        perldoc perlsyn
Look at the loops. In this case you can either use a while() loop 
(loop while the divisor is smaller than the sqrt(x) and it does not 
divide the tested number) and increment the divisor in the body or 
use a for() loop and break out of the loop if you find a divisor.

In both cases you'll have to be able to tell appart the cases when 
you found an integer divisor and when you run out of divisors to 
check.

Hope I'm making sense. It would be shorter to write the code for you, 
but that's exactly what I don't want to do.


Anyway you do want to look up the Erasthotenes sieve algorithm. It's 
more efficient.

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to