[erlang-questions] generating primes

Ben Fuhrmannek erlang@REDACTED
Mon Nov 24 11:33:13 CET 2008


Another approach to prime number generation:
http://en.wikipedia.org/wiki/Prime_number_formulas#Other_formulas

prime(N, Nfac1) ->
	Nfac = Nfac1 * N,
	Prime = 2 + ((2 * Nfac) rem (N+1)),
	case Prime of
		2 -> omit;
		_ ->
			io:format("~p~n", [Prime])
	end,
	prime(N+1, Nfac).

start: prime(1,1).




More information about the erlang-questions mailing list