Created
April 26, 2025 12:14
-
-
Save Nusab19/ed970d1a48753bfe7376cf4b68e002f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pylint:disable=W0621 | |
import math | |
def prime(n): | |
# Handle base cases | |
if n < 2: | |
return 0 | |
if n == 2 or n == 3: | |
return 1 | |
if n % 2 == 0 or n % 3 == 0: | |
return 0 | |
# Check only numbers of form 6k±1 up to sqrt(n) | |
i = 5 | |
while i * i <= n: | |
if n % i == 0 or n % (i + 2) == 0: | |
return 0 | |
i += 6 | |
return 1 | |
a = 10e6 | |
diff = 0 | |
prev = 2 | |
gap = 11 | |
for i in range(3, int(a)+1): | |
if prime(i): | |
k = i - prev | |
pd = diff | |
if k>diff: | |
print(f"{i: ^{gap}}-{prev: ^{gap}} = {i-prev}") | |
diff = max(diff, k) | |
prev = i | |
print(i,end='\r') | |
l = math.log10(i) | |
if l==int(l): | |
print('-'*33) | |
print(f"\nMax diff till 10e{int(l)}: {diff}\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment