Newbie - Trying to Help a Friend
Steven D'Aprano
steve at pearwood.info
Tue Nov 19 22:52:10 EST 2013
On Tue, 19 Nov 2013 22:10:55 -0500, Dave Angel wrote:
> On 20 Nov 2013 00:17:23 GMT, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> problem by hand. I'll get you started by solving the problem for 7.
>
>
>
>
>> Positive integers less than 23 are 1, 2, 3, 4, 5, 6. So let's start
>> checking them for divisors:
>
> Where did 23 come from?
/head-desk
Sorry, first draft of this post was going to go up to 23.
>> - 1 is not divisible by 2, 3 or 5, so we count one number. - 2 is
>> divisible by 2, but not by 3 or 5, so we count two numbers.
>
> 2 doesn't count because it's divisible by 2.
2 does count because it isn't divisible by 3. The question states,
"[count] how many positive integers less than N are not divisible by 2,3
or 5". Two is not divisible by 3, so "not divisible by 2,3 or 5" is true,
so two gets counted.
The first number which is divisible by *all* of 2, 3 and 5 (i.e. fails
the test, and therefore doesn't get counted) is 30. The next few that
fail the test are 60, 90, 120, 150, 180, 210, 240, 270, 300, ...
Remember, these are the numbers which should not be counted.
> I count 1, not 6
Out of curiosity, which number did you count?
--
Steven
More information about the Python-list
mailing list