DunningKruger

Discovered a Pattern Involving Powers of Odd Primes

Jan 10th, 2025 (edited)
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. # https://math.stackexchange.com/questions/5021626/discovered-a-pattern-involving-powers-of-odd-primes
  2.  
  3. import sympy
  4. from sympy import primerange
  5. from itertools import combinations
  6. from tabulate import tabulate
  7.  
  8. def generate_odd_primes(n):
  9. """
  10. Generate the first n odd prime numbers.
  11. """
  12. primes = list(primerange(3, sympy.prime(n) + 1))
  13. # Ensure we have exactly n primes
  14. while len(primes) < n:
  15. primes = list(primerange(3, sympy.prime(n) * 2))
  16. return primes[:n]
  17.  
  18. def find_consecutive_sum(digits, target):
  19. """
  20. Find a sequence of consecutive digits in the list `digits` that sums to `target`.
  21. Returns the first such sequence found.
  22. """
  23. length = len(digits)
  24. for window_size in range(1, length + 1):
  25. for i in range(length - window_size + 1):
  26. window = digits[i:i + window_size]
  27. if sum(window) == target:
  28. return window
  29. return None
  30.  
  31. def main():
  32. N = 10 # Number of cases to demonstrate
  33. primes = generate_odd_primes(N)
  34.  
  35. table = []
  36. for n in range(1, N + 1):
  37. p_n = primes[n - 1]
  38. p_n_power_n = pow(p_n, n)
  39. digits = [int(d) for d in str(p_n_power_n)]
  40. sequence = find_consecutive_sum(digits, p_n)
  41.  
  42. if sequence:
  43. S_pn = p_n
  44. sequence_str = ''.join(map(str, sequence))
  45. verification = f"{'+'.join(map(str, sequence))}={S_pn}"
  46. else:
  47. S_pn = "Not Found"
  48. sequence_str = "N/A"
  49. verification = "N/A"
  50. print(f"\n[ALERT] Sequence summing to p_n={p_n} not found in p_n^n={p_n_power_n}.\n")
  51. input("Press Enter to continue...") # Pause the program
  52.  
  53. table.append([n, p_n, p_n_power_n, verification])
  54.  
  55. headers = ["n", "p_n", "(p_n)^n", "S(p_n)"]
  56. print(tabulate(table, headers, tablefmt="grid"))
  57.  
  58. if __name__ == "__main__":
  59. main()
Advertisement
Add Comment
Please, Sign In to add comment