# irrSieve.py
# Fig 10.4 
# input: 20 or 2000

import math
import matplotlib.pyplot as plt

n = int(input("n=? "))
x = [1]*(2*n+1)  # available numbers
a = [0]*(2*n+1)  # irregular sequence 
i = 1; j = 1     # indicies for the two lists
a[j] = 1
while i < n: 
  x[i+j] = 0    # delete number i+j
  while True:   # look for an available number
    i += 1
    if x[i] == 1:   #  number i is available
      break
  j += 1
  a[j] = i   # store i in irregular sequence
print(f"{a[j]/j:.8f}")
plt.scatter(range(j+1), a[:j+1])
plt.xlabel('j')
plt.ylabel('a[j]')
plt.title('Irregular Sieve (n='+str(n)+')')
plt.show()
