Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # https://math.stackexchange.com/questions/5021626/discovered-a-pattern-involving-powers-of-odd-primes
- import sympy
- from sympy import primerange
- from itertools import combinations
- from tabulate import tabulate
- def generate_odd_primes(n):
- """
- Generate the first n odd prime numbers.
- """
- primes = list(primerange(3, sympy.prime(n) + 1))
- # Ensure we have exactly n primes
- while len(primes) < n:
- primes = list(primerange(3, sympy.prime(n) * 2))
- return primes[:n]
- def find_consecutive_sum(digits, target):
- """
- Find a sequence of consecutive digits in the list `digits` that sums to `target`.
- Returns the first such sequence found.
- """
- length = len(digits)
- for window_size in range(1, length + 1):
- for i in range(length - window_size + 1):
- window = digits[i:i + window_size]
- if sum(window) == target:
- return window
- return None
- def main():
- N = 10 # Number of cases to demonstrate
- primes = generate_odd_primes(N)
- table = []
- for n in range(1, N + 1):
- p_n = primes[n - 1]
- p_n_power_n = pow(p_n, n)
- digits = [int(d) for d in str(p_n_power_n)]
- sequence = find_consecutive_sum(digits, p_n)
- if sequence:
- S_pn = p_n
- sequence_str = ''.join(map(str, sequence))
- verification = f"{'+'.join(map(str, sequence))}={S_pn}"
- else:
- S_pn = "Not Found"
- sequence_str = "N/A"
- verification = "N/A"
- print(f"\n[ALERT] Sequence summing to p_n={p_n} not found in p_n^n={p_n_power_n}.\n")
- input("Press Enter to continue...") # Pause the program
- table.append([n, p_n, p_n_power_n, verification])
- headers = ["n", "p_n", "(p_n)^n", "S(p_n)"]
- print(tabulate(table, headers, tablefmt="grid"))
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment