Jump to content

10001th prime: Difference between revisions

Line 501:
104743</pre>
=={{header|Prolog}}==
<syntaxhighlightfor lang="swi-prolog">
</syntaxhighlight lang="prolog">isPrime(2).
isPrime(N):-
between(3, inf, N), % prime generator
N /\ 1 > 0, % odd
M is floor(sqrt(N)) - 1, % reverse 2*I+1
Max is M div 2,
forall(between(1, Max, I), N mod (2*I+1) > 0).
 
do:- Index is 10001,
findnsols(Index, N, isPrime(N), PrimeList),!,
last(PrimeList, PrimeAtIndex),
format('prime(~w) is ~w', [Index, PrimeAtIndex]), nl.</syntaxhighlight>
{{out}}
<pre>104743?- do.
prime(10001) is 104743</pre>
true.</pre>
 
=={{header|Python}}==
64

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.