Advertisement
krot

is_prime

Jul 20th, 2020
4,312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.22 KB | None | 0 0
  1. is_prime(N)->is_prime(N,2,erlang:trunc(math:sqrt(N))).
  2.  
  3. is_prime(1,_X,_E)->false;
  4. is_prime(2,_X,_E)->true;
  5. is_prime(N,X,_E) when N rem X ==0->false;
  6. is_prime(N,X,E) when X =< E->is_prime(N,X+1,E);
  7. is_prime(_N,_X,_E)->true.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement