Last active
July 30, 2024 21:02
-
-
Save orjanv/6d7393f22f1be67772fdbe39e16c59eb to your computer and use it in GitHub Desktop.
If a prime number is made up entirely of 1s (e.g., 11) then the number of its digits is prime.
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
# If a prime number is made up entirely of 1s (e.g., 11) | |
# then the number of its digits is prime. | |
from sympy import isprime | |
import sys | |
# ValueError: Exceeds the limit (4300 digits) for integer string | |
# conversion: value has 4301 digits; use sys.set_int_max_str_digits() | |
# to increase the limit | |
sys.set_int_max_str_digits(10000) | |
def main(): | |
num = 1 | |
while len(str(num)) < 10000: | |
if isprime(num): | |
num_sum = sum(int(x) for x in list(str(num))) | |
if isprime(num_sum): | |
print(f"{num} is prime, sum og length ({len(str(num))}), | |
{num_sum} is also prime") | |
num = num * 10 + 1 | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment