

from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
__A	:   Optional[int]	=					[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]




def        __UpperCamelCase     (      _A					:							int		)				->list[int]:



							"""simple docstring"""
							return [int(_A		) for c in f'{ruleset:08}'[:8]]




def        __UpperCamelCase     (      _A					:							list[list[int]]      ,  _A					:							list[int]      ,  _A					:							int		)				->list[int]:



							"""simple docstring"""
							lowerCamelCase_								=len(cells[0]		)  # 31
							lowerCamelCase_								=[]
							for i in range(_A		):
														# Get the neighbors of each cell
														# Handle neighbours outside bounds by using 0 as their value
														lowerCamelCase_								=0 if i == 0 else cells[time][i - 1]
														lowerCamelCase_								=0 if i == population - 1 else cells[time][i + 1]
														# Define a new cell and add it to the new generation
														lowerCamelCase_								=7 - int(f'{left_neighbor}{cells[time][i]}{right_neighbor}'      ,  2		)
														next_generation.append(rule[situation]		)
							return next_generation




def        __UpperCamelCase     (      _A					:							list[list[int]]		)				->Image.Image:



							"""simple docstring"""
							lowerCamelCase_								=Image.new("""RGB"""      ,  (len(cells[0]		), len(_A		))		)
							lowerCamelCase_								=img.load()
							# Generates image
							for w in range(img.width		):
														for h in range(img.height		):
																					lowerCamelCase_								=255 - int(255 * cells[h][w]		)
																					lowerCamelCase_								=(color, color, color)
							return img


if __name__ == "__main__":
	__A	:   str	=					bin(int(input('Rule:\n').strip()))[2:]
	__A	:   Union[str, Any]	=					format_ruleset(int(rule_num))
	for time in range(16):
		CELLS.append(new_generation(CELLS, rule, time))
	__A	:   Tuple	=					generate_image(CELLS)
	# Uncomment to save the image
	# img.save(f"rule_{rule_num}.png")
	img.show()



import math
from collections.abc import Generator




def        __UpperCamelCase     (      _A					:							int		)				->Generator[int, None, None]:



							"""simple docstring"""
							lowerCamelCase_								=(i for i in range(1      ,  (max_n + 1)		))
							for i in (n for n in numbers if n > 1):
														for j in range(2      ,  _A		):
																					if (i % j) == 0:
																												break
														else:
																					yield i




def        __UpperCamelCase     (      _A					:							int		)				->Generator[int, None, None]:



							"""simple docstring"""
							lowerCamelCase_								=(i for i in range(1      ,  (max_n + 1)		))
							for i in (n for n in numbers if n > 1):
														# only need to check for factors up to sqrt(i)
														lowerCamelCase_								=int(math.sqrt(_A		)		) + 1
														for j in range(2      ,  _A		):
																					if (i % j) == 0:
																												break
														else:
																					yield i




def        __UpperCamelCase     (      _A					:							int		)				->Generator[int, None, None]:



							"""simple docstring"""
							lowerCamelCase_								=(i for i in range(1      ,  (max_n + 1)      ,  2		))
							# It's useless to test even numbers as they will not be prime
							if max_n > 2:
														yield 2  # Because 2 will not be tested, it's necessary to yield it now
							for i in (n for n in numbers if n > 1):
														lowerCamelCase_								=int(math.sqrt(_A		)		) + 1
														for j in range(3      ,  _A      ,  2		):
																					# As we removed the even numbers, we don't need them now
																					if (i % j) == 0:
																												break
														else:
																					yield i




def        __UpperCamelCase     (      )				->Dict:



							"""simple docstring"""
							from timeit import timeit

							lowerCamelCase_								="""from __main__ import slow_primes, primes, fast_primes"""
							print(timeit("""slow_primes(1_000_000_000_000)"""      ,  setup=_A      ,  number=1000000		)		)
							print(timeit("""primes(1_000_000_000_000)"""      ,  setup=_A      ,  number=1000000		)		)
							print(timeit("""fast_primes(1_000_000_000_000)"""      ,  setup=_A      ,  number=1000000		)		)


if __name__ == "__main__":
	__A	:   Union[str, Any]	=					int(input('Calculate primes up to:\n>> ').strip())
	for ret in primes(number):
		print(ret)
	benchmark()
