Trying to solve equation

Hello

A bit of an odd ball question but I’m trying to solve a riddle and I believe this piece of python is a clue. Is anyone able to help? Thanks

def sieve(n):

Compute primes using sieve of Eraosthenes

x=[1]*n
x[1] = 0

for i in range (2,n/2):
		j = 2*i
		while j < n:
				x[j] = 0
				j = j+i
return x

def prime(n,x):

Find nth prime

i = 1
j = 1
while j <= n:
		if x[i] == 1:
      			j = j+1
		i = i+1
return i-1

The j = 1 may be wrong it may be j = i but it is hard to see in the original source as it is a low quality photo.

What sort of help are you asking for?

The Sieve of Eratosthenes is a well-known, and very ancient, method of
generating prime numbers.

If you only want to solve the riddle, you can probably cheat by just
looking up the list of prime numbers:

Here is the Sieve again, with a couple of small bugs fixed:

def sieve(n):
    x=[1]*n
    x[0] = x[1] = 0  # 0 and 1 are not prime.
    for i in range (2, n//2):
        j = 2*i
        while j < n:
            x[j] = 0
            j = j+i
    return x
1 Like

Thank for the help. I’ve come to realise this is a piece from an ex machina scene and the equation has been solved. Cheers!