# Iteration command doesnt work for NextPrime

mertkans shared this question 5 years ago

I want to define n th. prime by using iteration command, For example Iteration[NextPrime[x],2,100] to see 101th. prime. Is iteration command limited to use with only mathematical functions? 1

Hi,

in GGB, 4 iterations are : f( f( f( f(x) ) ) )

try :

Sequence[NextPrime, i, 2, 100] 1

Hi,

in GGB, 4 iterations are : f( f( f( f(x) ) ) )

try :

Sequence[NextPrime, i, 2, 100]

Sequence[NextPrime, i, 2, 100] command gives a list like {3,5,5,7,7,11,11,11,11,13,13,17,17,17...} because for i=4 it add list an element 5 and for 5 the same, so this command doesn't give 100th prime 1

:flushed:

try : with list1=Sequence[NextPrime, i, 2, 100]

Unique[list1]

or with just one command :

Unique[Sequence[NextPrime, i, 2, 100]] 1

:flushed:

try : with list1=Sequence[NextPrime, i, 2, 100]

Unique[list1]

or with just one command :

Unique[Sequence[NextPrime, i, 2, 100]]

Ok but this again doesn't give 100th prime gives 25th prime :) 1

Hi,

I guess

First[KeepIf[IsPrime[n],n,Sequence],100]

is the best option if you want to use commands. Number 1000 is a guess, it should be at least n*ln(n)*k where n is the number of primes you want to get and k is a suitable constant: https://en.wikipedia.org/wi...

A1=2

A2=NextPrime[A1]

copy A2 down by dragging

Cheers,

Zbynek 1

Try playing with:

Unique[Sequence[NextPrime, i, 2, n (ln(n) + ln(ln(n)) - 1)]]

https://primes.utm.edu/howmany.html