mhx@[EMAIL PROTECTED]
(Marcel Hendrix) writes Re: [SPOILER] Re: Euler problem #187
> anton@[EMAIL PROTECTED]
(Anton Ertl) writes Re: [SPOILER] Re:
Euler problem #187
>> I found and fixed the bug:
Never forget the old but nonetheless excellent work of others (in this
case Albert van der Horst).
-marcel
--
--------------------------------------------------------------------------------------
INCLUDE ../benchmar/benchpin.frt \ PI(N2) ( n1 -- n2 ) counts all primes
below n1
(*
A composite is a number containing at least two prime factors. For
example, 15 = 3 * 5; 9 = 3 * 3; 12 = 2 * 2 * 3.
There are ten composites below thirty containing precisely two, not
necessarily distinct, prime factors: 4, 6, 9, 10, 14, 15, 21, 22,
25, 26.
How many composite integers, n < 10^8, have precisely two, not
necessarily distinct, prime factors?
Solution:
---------
This is PI(n/i) - pi(i) + 1 for all primes i not greater than sqrt(n).
*)
: solution ( -- n )
0 #10000 2 DO I Prime? IF #100000000 I / PI(N2) I PI(N2) - 1+ + ENDIF
LOOP ;
: Euler187 ( -- )
CR ." There are " solution . ." composite integers, n < 10^8, having
precisely two, not "
CR ." necessarily distinct, prime factors." ;
\ FORTH> euler187
\ There are 17xxxxxx composite integers, n < 10^8, having precisely two,
not
\ necessarily distinct, prime factors.
\ 0.636 seconds elapsed. ok


|