Download - Explanation of Problem 1
-
8/2/2019 Explanation of Problem 1
1/2
Problem 1Sum of Truncatable Primes
Observation:
For a truncatable prime, both the right-most digit and the left-most digit must always be asingle digit prime number.For a truncatable prime, 2 and 5 can only appear as the left-most digit, because a numberending with 2 or 5 no longer remains a prime. Hence the right-most digit must be either 3
or 7.
For a left truncatable prime, one element among {1,2,3,5,7,9} only can appear as the leftmost digit.
Explanation of the Idea:
We need to build an array of left truncatable primes. We do this by finding the 2-digitleft truncatable prime first, then 3-digit left truncatable prime and so on.
We maintain a list of left truncatable primes LTList(say) but consider only 3 and 7 as 1digit left truncatable prime.
We maintain a list L={1,2,3,5,7,9} . Besides, we maintain a variable 'sum', initialized tozero that will finally contain the sum of all the 11 truncatable primes.
We also maintain 2 variables low and high which denote the upper and lower limits ofthe sub-list of LTList consisting of the left truncatable primes with the current number of
digits. So initially, 1 digited left truncatable primes are considered and low=0 and high=1
Now , to the left of each of the elements LTList, between low to high, we add each ofthe elements of the list L (one at a time) and check whether the resulting number is a
prime. If not discard it. If yes, then this new number is automatically a left truncatableprime and we add it to the LTList. If this new number is also right truncatable , then we
add this new number to 'sum'.
We continue until we have found the 11 truncatable primes.
Algorithm;
1. Initialize an array LTList (say) containing only 2 elements 3 and 7.2. Initialize count to 0, sum to 03. Initialize a variable 'low' to 0 and 'high' to 1. /*Generate the 2-digit truncatable primes*/4. Initialize the list L to {1,2,3,5,7,9}5. For each element of LTList between low to high
for each element of L
add the element of L to the left of the element of LTList
if the new number is a prime
add it to the list LTList
if the new number is a right truncatable prime
-
8/2/2019 Explanation of Problem 1
2/2
add new number to 'sum'
increment count
if count==11
goto step 8
6. Re assign low and high to reflect the new limits of the sub-array of LTLIst containing thecurrent-digited truncatable primes.
7. Go to step 5.8. Exit.As example, start with LTList={3,7}
I. Add 1 to the left of 3 and get 13.II. 13 is a prime. Add 13 to LTList
III. Similarly we get 17,23,27,33,37,53,57,73,77,93,97 and add 17,23,37,53,73,97to LTList .
IV. Since 23,37,53,73 are also right truncatable, so add each of them to 'sum'.V. At this point we have found all the 2-digited left truncatable primes and
thereby all the truncatable primes .
VI. Now we have count=4. So we make low=2 and high=8.VII. We continue the same process until we have reached count =11.