We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
# Enter your code here. Read input from STDIN. Print output to STDOUTdefis_prime(n):ifn<2:returnFalseforiinrange(2,int(n**0.5)+1):ifn%i==0:returnFalsereturnTruedefis_truncatable(n):s=str(n)foriinrange(1,len(s)):ifnotis_prime(int(s[i:]))ornotis_prime(int(s[:i])):returnFalsereturnTruelimit=int(input())trunc_primes=[]forpinrange(10,limit):ifis_prime(p)andis_truncatable(p):trunc_primes.append(p)print(sum(trunc_primes))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #37: Truncatable primes
You are viewing a single comment's thread. Return to all comments →
100 points