Erlang で Project Euler #3 をコーディングしようとしています:
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
これが私のコードです:
-module(problem_3).
-compile(export_all).
start()->
problem_3(600851475143, 2).
problem_3(Num, F) when Num > 1 ->
case Num rem F of
0 ->
problem_3(Num / F, F);
1 ->
problem_3(Num, F + 1)
end;
problem_3(Num, F) ->
io:format("result: ~p~n", [F]).
しかし、このコードには 2 つの問題があります。
5> problem_3:start().
** exception error: no case clause matching 2
in function problem_3:problem_3/2
6> problem_3:problem_3(10, 2).
** exception error: bad argument in an arithmetic expression
in function problem_3:problem_3/2
このエラーが発生する理由と修正方法を教えてください。