Project Euler

Problem #204

A Hamming number is a positive number which has no prime factor larger than 5.
So the first few Hamming numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15.
There are 1105 Hamming numbers not exceeding 10^(8).

We will call a positive number a generalised Hamming number of type n, if it has no prime factor larger than n.
Hence the Hamming numbers are the generalised Hamming numbers of type 5.

How many generalised Hamming numbers of type 100 are there which don't exceed 10^(9)?

Erlang: Running time = 4.476s
+%echo

+%prime_list

+%prime_iterator

%
% The idea here is to simply walk through the entire prime factorization tree,
% counting each number one by one.
%

p204()->
	Iter=prime_iterator(self()),
	Primes=p204(get_primes,Iter,[]),
	io:format("~w~n",[p204(compute,1,Primes)]).

p204(help_compute,_,[],Sum)->Sum;
p204(help_compute,Base,List,Sum)->
	[Next|Rest]=List,
	p204(help_compute,Base,Rest,Sum+p204(compute,Base*Next,List)).
p204(compute,_,[])->0;
p204(compute,Base,Using) when Base > 1000000000->0;
p204(compute,Base,Using)->
	1+p204(help_compute,Base,Using,0);

p204(get_primes,Iter,L)->
	Iter ! next,
	receive
		{prime,N}->
			if
				N>100->L;
				true->p204(get_primes,Iter,[N|L])
			end
	end.