[Python] Python - Prime Shift[Python] Python - Prime Shift

🧮

Primes

Week 8, 2026

import math def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False limit = int(math.sqrt(n)) + 1 for i in range(3, limit, 2): if n % i == 0: return False return True store = [] minus_one_count = 0 add_one_count = 0 previous_x = None for x in range(1, 10001): value_minus = x*x - 1 if is_prime(value_minus): minus_one_count += 1 if previous_x is None: diff = x else: diff = x - previous_x store.append(f"{x}^2 - 1 = {value_minus}") store.append(f"Difference: {diff}\n") previous_x = x value_plus = x*x + 1 if is_prime(value_plus): add_one_count += 1 if previous_x is None: diff = x else: diff = x - previous_x store.append(f"{x}^2 + 1 = {value_plus}") store.append(f"Difference: {diff}\n") previous_x = x store.append("--- Counts ---") store.append(f"MinusOneCount: {minus_one_count}") store.append(f"AddOneCount: {add_one_count}") file = open("ans.txt", 'w') for line in store: file.write(line+'\n') file.close() print("Process completed")