Let
a
be an
n
digit palindrome.
Let
f
(
x
)
=
the sum of the digits of
x
.
Given that there are 13 values such that
a
is prime and
a
+
f
(
a
)
is also prime,
what is the value of
n
?
Example
-
3
8
3
is a prime palindrome
-
f
(
3
8
3
)
=
3
+
8
+
3
=
1
4
-
3
8
3
+
f
(
3
8
3
)
=
3
9
7
which is also prime
I also made a slightly harder version of this problem - Primey Palindromes V2
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Wrote the following code to solve this problem. Got result in 0.01 sec.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
Wow 0.01 seconds is really good!! :D
Log in to reply
Actually first I thought of solving it manually but after 15 mins I realized that I must write the code. :P :D
This code takes just 0.25 secs to list all the palindromic primes less than 10000000000 that satisfy the given constraints. So this runs in fractions of milliseconds to solve this problem. Seems to be fastest running code.
1 2 3 4 5 6 7 8 9 10 11 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
Uses code from the Python sympy library to supply primes in n-digit range. Has all the tests for suitable numbers (palindromic, etc) in a single function.
I used prime palindrome number in Google. Number with middle term even would give, summation of digits as even. Our number is odd so this would give us ..a + f(a).. also as odd. Checked from Google if it was prime or not. 98689 was the 13th number ..with...
..a + f(a)..=98729..... Note even digit palindrome will never be prime since it will always be divisible by 11.
PalindromeQ[n_] := Catch[ s = IntegerDigits[n]; Do[ If[s[[i]] != s[[Length[s] - i + 1]], Throw[False]] , {i, Ceiling[Length[s]/2]}] Throw[True] ]
DigitSum[n_] := Total[IntegerDigits[n, 10]]
Do[ If[PalindromeQ[Prime[n]] && PrimeQ[Prime[n] + DigitSum[Prime[n]]], Print[Prime[n]]] , {n, 1000000}]
Then I saw the output for 5 digits :)
Problem Loading...
Note Loading...
Set Loading...
python3.4