10001th prime: Difference between revisions

Content added Content deleted
No edit summary
Line 660: Line 660:
<syntaxhighlight lang="pascal">
<syntaxhighlight lang="pascal">
Prime(10001);
Prime(10001);
</syntaxhighlight>
{{out}}<pre>104743</pre>

=={{header|FreePascal}}==
<syntaxhighlight lang="pascal">
Program nth_prime;

Function nthprime(x : uint32): uint32;
Var primes : array Of uint32;
i,pr,count : uint32;
found : boolean;
Begin
setlength(primes, x);
primes[1] := 2;
count := 1;
i := 3;
Repeat
found := FALSE;
pr := 0;
Repeat
inc(pr);
found := i Mod primes[pr] = 0;
Until (primes[pr]*primes[pr] > i) Or found;
If Not found Then
Begin
inc(count);
primes[count] := i;
End;
inc(i,2);
Until count = x;
nthprime := primes[x];
End;

Begin
writeln(nthprime(10001));
End.

</syntaxhighlight>
</syntaxhighlight>
{{out}}<pre>104743</pre>
{{out}}<pre>104743</pre>
Line 951: Line 914:
<syntaxhighlight lang="parigp">prime(10001)</syntaxhighlight>
<syntaxhighlight lang="parigp">prime(10001)</syntaxhighlight>
{{out}}<pre>%1 = 104743</pre>
{{out}}<pre>%1 = 104743</pre>

=={{header|Pascal}}==
==={{header|Free Pascal}}===
<syntaxhighlight lang="pascal">
Program nth_prime;

Function nthprime(x : uint32): uint32;
Var primes : array Of uint32;
i,pr,count : uint32;
found : boolean;
Begin
setlength(primes, x);
primes[1] := 2;
count := 1;
i := 3;
Repeat
found := FALSE;
pr := 0;
Repeat
inc(pr);
found := i Mod primes[pr] = 0;
Until (primes[pr]*primes[pr] > i) Or found;
If Not found Then
Begin
inc(count);
primes[count] := i;
End;
inc(i,2);
Until count = x;
nthprime := primes[x];
End;

Begin
writeln(nthprime(10001));
End.
</syntaxhighlight>
{{out}}
<pre>
104743
</pre>


=={{header|Perl}}==
=={{header|Perl}}==