# public ndpar /algorithms

### Subversion checkout URL

You can clone with HTTPS or Subversion.

 ``` dc4e79d1 » Andrey Paramonov ``` 2010-05-08 More problems solved 1 %% Problem 2 %% --------------------- 3 %% The first two consecutive numbers to have two distinct prime factors are: 4 %% 5 %% 14 = 2 x 7 6 %% 15 = 3 x 5 7 %% 8 %% The first three consecutive numbers to have three distinct prime factors are: 9 %% 10 %% 644 = 2^2 x 7 x 23 11 %% 645 = 3 x 5 x 43 12 %% 646 = 2 x 17 x 19. 13 %% 14 %% Find the first four consecutive integers to have four distinct primes factors. 15 %% What is the first of these numbers? 16 %% --------------------- 17 18 % http://www.research.att.com/~njas/sequences/A075044 19 20 -module(p047). 21 -export([solve/0]). 22 23 24 solve() -> check(37963). % three consecutive with four prime factors 25 26 check(N) -> check(N, mymath:primes_upto(135000), []). 27 28 check(_, _, [P,Q,R,S]) -> [S,R,Q,P]; 29 check(N, Primes, Acc) -> 30 case lists:member(N, Primes) of 31 true -> check(N+1, Primes, []); 32 _ -> 33 F = lists:usort(mymath:factorisation(N, Primes, [])), 34 case length(F) of 35 4 -> 36 check(N+1, Primes, [N|Acc]); 37 _ -> 38 check(N+1, Primes, []) 39 end 40 end.