Showing posts with label square numbers. Show all posts
Showing posts with label square numbers. Show all posts

Saturday, 23 August 2025

Fun With Primes and Digit Pairs

One of the interesting mathematical facts about the number associated with my diurnal age today, \( \textbf{27901} \), is that it is prime and the sums of all pairs of its successive digits are \( \textbf{square} \) numbers. We have:$$ \begin{align} 2 + 7 &= 9 = 3^2 \\ 7 + 9 &= 16 = 4^2 \\ 9 + 0 &= 9 = 3^2 \\ 0+1 &= 1 = 1^2 \end{align}$$Such numbers are few and far between. In fact, up to 40000, there are only 41 of them and they belong to OEIS A108659 (permalink):

\( \textbf{primes with the sums of all pairs of successive digits square} \)

13, 31, 79, 97, 101, 109, 131, 181, 227, 313, 401, 409, 631, 727, 797, 881, 1009, 1013, 1097, 2797, 3109, 3181, 3631, 4001, 4013, 7901, 8101, 9001, 9013, 10009, 10181, 10909, 10979, 13109, 18131, 18181, 22279, 22727, 27901, 31013, 36313

If a number is prime and the sums of all pairs of successive digits are \( \textbf{prime} \) as well then we find that there are 160 numbers that qualify in the range up 40000 (permalink):

\( \textbf{primes with the sums of all pairs of successive digits prime} \)

11, 23, 29, 41, 43, 47, 61, 67, 83, 89, 149, 167, 211, 307, 347, 349, 383, 389, 503, 521, 523, 743, 761, 929, 941, 947, 983, 1123, 1129, 2029, 2111, 2129, 2141, 2143, 2161, 2341, 2347, 2383, 2389, 2503, 2521, 3023, 3203, 4111, 4129, 4349, 4703, 4943, 5021, 5023, 6121, 6143, 6521, 6529, 6703, 6761, 7411, 8329, 8389, 8521, 8923, 8929, 8941, 9203, 11149, 11161, 11411, 12143, 12149, 12161, 12323, 12329, 12343, 12347, 12503, 12583, 12589, 12923, 12941, 12983, 14143, 14149, 14303, 14321, 14323, 14341, 14347, 14389, 14741, 14747, 14767, 14923, 14929, 14947, 14983, 16111, 16141, 16529, 16561, 16567, 16703, 16741, 16747, 20323, 20341, 20347, 20389, 20507, 20521, 20707, 20743, 20747, 20749, 21121, 21143, 21149, 21211, 21611, 23021, 23029, 23203, 29207, 29411, 30203, 30211, 30307, 30323, 30341, 30347, 30389, 30529, 30703, 30707, 32029, 32141, 32143, 32303, 32321, 32323, 32341, 32503, 32507, 32561, 32941, 32983, 34123, 34129, 34141, 34147, 34303, 34703, 34747, 34949, 38303, 38321, 38329, 38561, 38567, 38921, 38923

Let's take the final number, \( \textbf{38923} \), above as an example. We have:$$ \begin{align} 3 + 8 &=11\\8 + 9 &= 17 \\ 9+2 &=11\\2+3 &=5 \end{align}$$We can add an additional constraint here and that is that the \( \textbf{first and last digits} \) be considered adjacent and prime as well. In this case, the suitable numbers in the range up to 40000 shrink to 60. These numbers belong to OEIS A086244 (permalink):$$ \begin{align} &\textbf{primes with the sums of all pairs of successive } \\  &\textbf{digits prime as well as sums of first and last digits} \end{align}$$11, 23, 29, 41, 43, 47, 61, 67, 83, 89, 211, 2029, 2111, 2129, 2141, 2143, 2161, 2341, 2383, 2389, 2503, 2521, 4111, 4129, 4349, 4703, 4943, 6121, 6521, 6761, 8329, 8389, 8923, 8929, 11161, 11411, 12161, 12941, 14321, 14341, 14741, 16111, 16141, 16561, 16741, 20323, 20341, 20389, 20521, 20743, 20749, 21121, 21143, 21149, 21211, 21611, 23021, 23029, 23203, 29411

Let's take the final number in the previous list, \( \textbf{29411} \), and show that it satisfies the criteria:$$ \begin{align} 2 + 9 &= 11 \\ 9 + 4 &= 13 \\ 4 + 1 &= 5 \\ 1 + 1 &= 2 \\ 2 + 1 &= 3 \end{align}$$We can also consider primes where the absolute values of \( \textbf{differences} \) between successive pairs of digits are prime. There are 272 of these in the range up to 40000. They constitute OEIS A087593 (permalink):$$ \begin{align} &\textbf{primes with the absolute differences} \\  &\textbf{of all pairs of successive digits prime} \end{align} $$13, 29, 31, 41, 47, 53, 61, 79, 83, 97, 131, 149, 163, 181, 241, 257, 307, 313, 353, 383, 461, 463, 479, 503, 613, 631, 641, 647, 683, 727, 757, 797, 853, 857, 863, 929, 941, 947, 1303, 1307, 1361, 1381, 1427, 1429, 1613, 1697, 1831, 1861, 2027, 2029, 2053, 2503, 2531, 2579, 2707, 2729, 2741, 2749, 2753, 2797, 2927, 2963, 2969, 3079, 3163, 3169, 3181, 3527, 3529, 3581, 3583, 3613, 3631, 3697, 3853, 3863, 4241, 4253, 4297, 4649, 4703, 4729, 4969, 5279, 5297, 5303, 5381, 5741, 5749, 5813, 5857, 5861, 5869, 6131, 6163, 6353, 6361, 6427, 6469, 6857, 6863, 6869, 6947, 6949, 6961, 7027, 7057, 7079, 7207, 7247, 7253, 7297, 7507, 7529, 7583, 7927, 7949, 7963, 8147, 8161, 8353, 8363, 8369, 8527, 8581, 8641, 8647, 8681, 9203, 9241, 9257, 9413, 9461, 9463, 9479, 9497, 9613, 9631, 9649, 9697, 9749, 13147, 13163, 13183, 13613, 13649, 13681, 13697, 13831, 14149, 14207, 14249, 14683, 14741, 14747, 14753, 14797, 14929, 14947, 14969, 16141, 16183, 16361, 16363, 16369, 16381, 16427, 16831, 16927, 16963, 16979, 18131, 18149, 18169, 18181, 18307, 18313, 18353, 18503, 18583, 20249, 20297, 20353, 20357, 20369, 20507, 20707, 20747, 20749, 20753, 24169, 24181, 24203, 24247, 24631, 24683, 24697, 24749, 24979, 25031, 25057, 25247, 25253, 25303, 25307, 25357, 25703, 25741, 25747, 27031, 27241, 27253, 27427, 27479, 27527, 27529, 27581, 27583, 27941, 27947, 27961, 29207, 29297, 29429, 29641, 29683, 29741, 29753, 30203, 30241, 30253, 30307, 30313, 30529, 30703, 30707, 30727, 30757, 31307, 31357, 31469, 31649, 35027, 35053, 35257, 35279, 35353, 35363, 35381, 35729, 35747, 35753, 35797, 35831, 35863, 35869, 36131, 36161, 36307, 36313, 36353, 36383, 36469, 36479, 36497, 36857, 36929, 36947, 36979, 38149, 38183, 38303

Let's take the last number, \( \textbf{38303}\), in the list above. We have:$$ \begin{align} |3-8|=5 \\ |8 - 3|=5 \\ |3-0|=3 \\ |0-3|=3 \end{align}$$There are all sorts of variations on this theme (the properties of pairs of adjacent digits) and so another approach is to consider the squares of the digits. Let's require that the sums of squares of adjacent digits be prime. We find that there are 71 numbers that qualify in the range up to 40000. These are (permalink):$$ \begin{align} \textbf{primes with the sums of all pairs}\\ \textbf{of successive digits squared prime} \end{align} $$11, 23, 41, 61, 83, 127, 149, 211, 383, 521, 523, 541, 587, 727, 787, 941, 1123, 2111, 2141, 2161, 2383, 2521, 2549, 4111, 4127, 4523, 4549, 4561, 4583, 6121, 6521, 7211, 8387, 8521, 8527, 8783, 11149, 11161, 11411, 12149, 12161, 12323, 12527, 12541, 12583, 12721, 14149, 14549, 14561, 16111, 16127, 16141, 16561, 21121, 21149, 21211, 21611, 25411, 27211, 32141, 32321, 32323, 32327, 32561, 32587, 32783, 38321, 38327, 38561, 38723, 38783

Let's take the last number, \( \textbf{38783} \), as an example:$$ \begin{align} 3^2+8^2 &= 9 + 64 =73 \\ 8^2+7^2 &= 64 +49 = 113 \\ 7^2+8^2 &= 49+64 = 113 \\ 8^2+3^2 &= 64 + 9 = 73 \end{align}$$

Saturday, 1 March 2025

Efficient Sorting Algorithm

 Here is a problem that I came across today. Here is the link.


Place each of the numbers from 1 to 15 into the spaces provided so that the sum of any two consecutive spaces is a square number. The following clue was provided: the number 8 must be placed on one end and the number 9 must be placed on the other end.

Without the clue, there are a staggering 1,307,674,368,000 possible permutations (that's over one trillion) but with the clue this reduces to 6,227,020,800 or a little over six billion. However, the clue is very helpful because we know that next to 8 we can only place a 1 and next to the 9 we can only place a 7. So we have:$$9, 7, x, x, x, x, x, x, x, x, x, x, x, 1, 8$$Now next to the 7 we can only place a 2 and next to the 1 we can only place a 15, so we now have:$$9, 7, 2, x, x, x, x, x, x, x, x, x, 15, 1, 8$$Next to the 2 we can only place 14 and next to the 15 we can only place a 10. This gives$$9, 7, 2, 14, x, x, x, x, x, x, x, 10, 15, 1, 8$$Continuing this process, we find 14 can only be paired with 11 and 10 with 6. We now have:$$9, 7, 2, 14, 11, x, x, x, x, x, 6, 10, 15, 1, 8$$We then quickly reach our solution:



The key to solving the problem is to begin and end the sequence of numbers with 8 and 9 or vice versa because these two initial choices determine all the remaining numbers. I asked Gemini to write a Python program to solve the problem but without giving it any clues. I also asked it to explain its thinking. Figure 1 is what it came up with, in about 67 lines of code.


Figure 1: Gemini Link

Here is how Gemini described its thinking:
\( \textbf{Reasoning and Strategies:}\)

is_square(n) \( \textbf{Function} \):
  • This function efficiently checks if a number is a perfect square. It calculates the integer square root and compares its square to the original number. 
find_next(current_sequence, remaining_numbers) \( \textbf{Function (Recursive Backtracking:)} \)
  • This function uses recursion to explore possible sequences.
  • It checks if the current sequence is complete (no remaining numbers).
  • For each remaining number, it checks if it forms a square sum with the last number in the current sequence.
  • If a square sum is found, it adds the number to the sequence and recursively calls itself with the updated sequence and remaining numbers.
  • If no valid next number is found, it backtracks. 
\( \textbf{Optimization} \) 
\( \textbf{Precompute Possible Pairs (Graph Representation): }  \)
  • Instead of repeatedly checking for square sums, we precompute all possible pairs of numbers that add to a square.
  • This is stored in the possible_pairs dictionary, which represents a graph where numbers are nodes, and edges exist between numbers that form a square sum.
  • This optimization significantly reduces the number of square sum calculations. 
\( \textbf{Optimization} \) 
\( \textbf{Start with Numbers with Fewer Possible Pairs:} \)
  • The sorted_numbers list is created by sorting the numbers based on the number of possible pairs they have.
  • Starting the search with numbers that have fewer possible pairs reduces the branching factor in the recursive search. This means the algorithm explores fewer potential paths, leading to faster results.
  • This is a heuristic that helps avoid exploring large portions of the search space that are unlikely to lead to a solution. 
\( \textbf{Backtracking Efficiency}: \)
  • The recursive backtracking algorithm is designed to efficiently explore the search space. When a dead end is encountered (no valid next number), the algorithm immediately backtracks to the previous decision point, avoiding unnecessary exploration of other paths.
  • By combining the precomputation of possible pairs and the heuristic of starting with numbers with fewer options, the backtracking algorithm becomes much more efficient than a naive brute-force approach.
The algorithm (permalink) is easily adapted for longer runs of numbers. For example, let's say we want to arrange the number from 1 to 35. Here is one configuration (generated almost instantly):

[18, 7, 2, 14, 11, 5, 31, 33, 3, 22, 27, 9, 16, 20, 29, 35, 1, 8, 28, 21, 4, 32, 17, 19, 6, 30, 34, 15, 10, 26, 23, 13, 12, 24, 25] ... permalink

Sunday, 9 July 2023

Concatenations of Squares and Cubes

I was surprised that the number associated with my diurnal age today, 27125, didn't show up in the OEIS as a concatenation of two cubes, namely \(3^3\) and \(5^3\). This prompted me to list all numbers of the form \(n^3 \, | \, m^3\) where \(n\) and \(m\) are integers (not necessarly distinct). Here is a permalink to the SageMath code that generates the list up to 40,000 and here is the list:

11, 18, 81, 88, 127, 164, 271, 278, 641, 648, 827, 864, 1125, 1216, 1251, 1258, 1343, 1512, 1729, 2161, 2168, 2727, 2764, 3431, 3438, 5121, 5128, 6427, 6464, 7291, 7298, 8125, 8216, 8343, 8512, 8729, 10001, 10008, 11000, 11331, 11728, 12197, 12527, 12564, 12744, 13311, 13318, 13375, 14096, 14913, 15832, 16859, 17281, 17288, 18000, 19261, 21627, 21664, 21971, 21978, 27125, 27216, 27343, 27441, 27448, 27512, 27729, 33751, 33758, 34327, 34364

Some are more difficult to spot than others. What about concatenations of square numbers? Here is a permalink to the SageMath code that generates a list of numbers up to 40,000 and here is the list of numbers of the form  \(n^2 \, | \, m^2\) where \(n\) and \(m\) are integers (not necessarly distinct):

11, 14, 19, 41, 44, 49, 91, 94, 99, 116, 125, 136, 149, 161, 164, 169, 181, 251, 254, 259, 361, 364, 369, 416, 425, 436, 449, 464, 481, 491, 494, 499, 641, 644, 649, 811, 814, 819, 916, 925, 936, 949, 964, 981, 1001, 1004, 1009, 1100, 1121, 1144, 1169, 1196, 1211, 1214, 1219, 1225, 1256, 1289, 1324, 1361, 1400, 1441, 1444, 1449, 1484, 1529, 1576, 1616, 1625, 1636, 1649, 1664, 1676, 1681, 1691, 1694, 1699, 1729, 1784, 1841, 1900, 1961, 1964, 1969, 2251, 2254, 2259, 2516, 2525, 2536, 2549, 2561, 2564, 2569, 2581, 2891, 2894, 2899, 3241, 3244, 3249, 3611, 3614, 3616, 3619, 3625, 3636, 3649, 3664, 3681, 4001, 4004, 4009, 4100, 4121, 4144, 4169, 4196, 4225, 4256, 4289, 4324, 4361, 4400, 4411, 4414, 4419, 4441, 4484, 4529, 4576, 4625, 4676, 4729, 4784, 4841, 4844, 4849, 4900, 4916, 4925, 4936, 4949, 4961, 4964, 4981, 5291, 5294, 5299, 5761, 5764, 5769, 6251, 6254, 6259, 6416, 6425, 6436, 6449, 6464, 6481, 6761, 6764, 6769, 7291, 7294, 7299, 7841, 7844, 7849, 8116, 8125, 8136, 8149, 8164, 8181, 8411, 8414, 8419, 9001, 9004, 9009, 9100, 9121, 9144, 9169, 9196, 9225, 9256, 9289, 9324, 9361, 9400, 9441, 9484, 9529, 9576, 9611, 9614, 9619, 9625, 9676, 9729, 9784, 9841, 9900, 9961, 10016, 10025, 10036, 10049, 10064, 10081, 10241, 10244, 10249, 10891, 10894, 10899, 11024, 11089, 11156, 11225, 11296, 11369, 11444, 11521, 11561, 11564, 11569, 11600, 11681, 11764, 11849, 11936, 12025, 12116, 12125, 12136, 12149, 12164, 12181, 12209, 12251, 12254, 12259, 12304, 12401, 12500, 12601, 12704, 12809, 12916, 12961, 12964, 12969, 13025, 13136, 13249, 13364, 13481, 13600, 13691, 13694, 13699, 13721, 13844, 13969, 14096, 14225, 14356, 14416, 14425, 14436, 14441, 14444, 14449, 14464, 14481, 14489, 14624, 14761, 14900, 15041, 15184, 15211, 15214, 15219, 15329, 15476, 15625, 15776, 15929, 16001, 16004, 16009, 16084, 16100, 16121, 16144, 16169, 16196, 16225, 16241, 16256, 16289, 16324, 16361, 16400, 16441, 16484, 16529, 16561, 16576, 16625, 16676, 16724, 16729, 16784, 16811, 16814, 16819, 16841, 16889, 16900, 16916, 16925, 16936, 16949, 16961, 16964, 16981, 17056, 17225, 17396, 17569, 17641, 17644, 17649, 17744, 17921, 18100, 18281, 18464, 18491, 18494, 18499, 18649, 18836, 19025, 19216, 19361, 19364, 19369, 19409, 19604, 19616, 19625, 19636, 19649, 19664, 19681, 19801, 20251, 20254, 20259, 21161, 21164, 21169, 22091, 22094, 22099, 22516, 22525, 22536, 22549, 22564, 22581, 23041, 23044, 23049, 24011, 24014, 24019, 25001, 25004, 25009, 25100, 25121, 25144, 25169, 25196, 25225, 25256, 25289, 25324, 25361, 25400, 25441, 25484, 25529, 25576, 25616, 25625, 25636, 25649, 25664, 25676, 25681, 25729, 25784, 25841, 25900, 25961, 26011, 26014, 26019, 27041, 27044, 27049, 28091, 28094, 28099, 28916, 28925, 28936, 28949, 28964, 28981, 29161, 29164, 29169, 30251, 30254, 30259, 31361, 31364, 31369, 32416, 32425, 32436, 32449, 32464, 32481, 32491, 32494, 32499, 33641, 33644, 33649, 34811, 34814, 34819, 36001, 36004, 36009, 36100, 36116, 36121, 36125, 36136, 36144, 36149, 36164, 36169, 36181, 36196, 36225, 36256, 36289, 36324, 36361, 36400, 36441, 36484, 36529, 36576, 36625, 36676, 36729, 36784, 36841, 36900, 36961, 37211, 37214, 37219, 38441, 38444, 38449, 39691, 39694, 39699

We can thin the above list of numbers by requiring that the number formed by the concatenation be a square number (permalink):

49, 169, 361, 1225, 1444, 1681, 3249, 4225, 4900, 15625, 16900, 36100

Here we see that \(36100 = 6^2 \, | \, 10^2 = 190^2 \).

While we're at it, let's consider concatenations of fourth powers. Here is a list (permalink) of numbers of the form \(n^4 \, | \, m^4\) where \(n\) and \(m\) are integers (not necessarly distinct):

11, 116, 161, 181, 811, 1256, 1616, 1625, 1681, 2561, 6251, 8116, 8181, 11296, 12401, 12961, 14096, 16256, 16561, 16625, 24011, 25616, 25681

We don't have to limit ourselves to concatenations of pairs of powers. We can concatenate three powers as easily as two. Let's consider numbers that are a concatenation of three square numbers (permalink):

111, 114, 119, 141, 144, 149, 191, 194, 199, 411, 414, 419, 441, 444, 449, 491, 494, 499, 911, 914, 919, 941, 944, 949, 991, 994, 999, 1116, 1125, 1136, 1149, 1161, 1164, 1169, 1181, 1251, 1254, 1259, 1361, 1364, 1369, 1416, 1425, 1436, 1449, 1464, 1481, 1491, 1494, 1499, 1611, 1614, 1619, 1641, 1644, 1649, 1691, 1694, 1699, 1811, 1814, 1819, 1916, 1925, 1936, 1949, 1964, 1981, 2511, 2514, 2519, 2541, 2544, 2549, 2591, 2594, 2599, 3611, 3614, 3619, 3641, 3644, 3649, 3691, 3694, 3699, 4116, 4125, 4136, 4149, 4161, 4164, 4169, 4181, 4251, 4254, 4259, 4361, 4364, 4369, 4416, 4425, 4436, 4449, 4464, 4481, 4491, 4494, 4499, 4641, 4644, 4649, 4811, 4814, 4819, 4911, 4914, 4916, 4919, 4925, 4936, 4941, 4944, 4949, 4964, 4981, 4991, 4994, 4999, 6411, 6414, 6419, 6441, 6444, 6449, 6491, 6494, 6499, 8111, 8114, 8119, 8141, 8144, 8149, 8191, 8194, 8199, 9116, 9125, 9136, 9149, 9161, 9164, 9169, 9181, 9251, 9254, 9259, 9361, 9364, 9369, 9416, 9425, 9436, 9449, 9464, 9481, 9491, 9494, 9499, 9641, 9644, 9649, 9811, 9814, 9819, 9916, 9925, 9936, 9949, 9964, 9981, 10011, 10014, 10019, 10041, 10044, 10049, 10091, 10094, 10099, 11001, 11004, 11009, 11100, 11121, 11144, 11169, 11196, 11211, 11214, 11219, 11225, 11256, 11289, 11324, 11361, 11400, 11441, 11444, 11449, 11484, 11529, 11576, 11616, 11625, 11636, 11649, 11664, 11676, 11681, 11691, 11694, 11699, 11729, 11784, 11841, 11900, 11961, 11964, 11969, 12111, 12114, 12119, 12141, 12144, 12149, 12191, 12194, 12199, 12251, 12254, 12259, 12516, 12525, 12536, 12549, 12561, 12564, 12569, 12581, 12891, 12894, 12899, 13241, 13244, 13249, 13611, 13614, 13616, 13619, 13625, 13636, 13649, 13664, 13681, 14001, 14004, 14009, 14100, 14121, 14144, 14169, 14196, 14225, 14256, 14289, 14324, 14361, 14400, 14411, 14414, 14419, 14441, 14444, 14449, 14484, 14491, 14494, 14499, 14529, 14576, 14625, 14676, 14729, 14784, 14841, 14844, 14849, 14900, 14916, 14925, 14936, 14949, 14961, 14964, 14981, 15291, 15294, 15299, 15761, 15764, 15769, 16116, 16125, 16136, 16149, 16161, 16164, 16169, 16181, 16251, 16254, 16259, 16361, 16364, 16369, 16416, 16425, 16436, 16449, 16464, 16481, 16491, 16494, 16499, 16641, 16644, 16649, 16761, 16764, 16769, 16811, 16814, 16819, 16911, 16914, 16916, 16919, 16925, 16936, 16941, 16944, 16949, 16964, 16981, 16991, 16994, 16999, 17291, 17294, 17299, 17841, 17844, 17849, 18116, 18125, 18136, 18149, 18164, 18181, 18411, 18414, 18419, 19001, 19004, 19009, 19100, 19121, 19144, 19169, 19196, 19225, 19256, 19289, 19324, 19361, 19400, 19441, 19484, 19529, 19576, 19611, 19614, 19619, 19625, 19641, 19644, 19649, 19676, 19691, 19694, 19699, 19729, 19784, 19841, 19900, 19961, 22511, 22514, 22519, 22541, 22544, 22549, 22591, 22594, 22599, 25116, 25125, 25136, 25149, 25161, 25164, 25169, 25181, 25251, 25254, 25259, 25361, 25364, 25369, 25416, 25425, 25436, 25449, 25464, 25481, 25491, 25494, 25499, 25611, 25614, 25619, 25641, 25644, 25649, 25691, 25694, 25699, 25811, 25814, 25819, 25916, 25925, 25936, 25949, 25964, 25981, 28911, 28914, 28919, 28941, 28944, 28949, 28991, 28994, 28999, 32411, 32414, 32419, 32441, 32444, 32449, 32491, 32494, 32499, 36111, 36114, 36116, 36119, 36125, 36136, 36141, 36144, 36149, 36161, 36164, 36169, 36181, 36191, 36194, 36199, 36251, 36254, 36259, 36361, 36364, 36369, 36416, 36425, 36436, 36449, 36464, 36481, 36491, 36494, 36499, 36641, 36644, 36649, 36811, 36814, 36819, 36916, 36925, 36936, 36949, 36964, 36981

Here we see that \(36981= 6^2 \, | \, 3^2 \, | \,9^2\). Once again, we can thin the above numbers by adding the requirement that the number formed by the concatenation be a square number. In this case, we get (permalink):

144, 441, 1369, 1936, 11449, 11664, 14400, 16641, 36481

Here we see that \(36481=6^2 \, | \, 2^2 \, | \,9^2 = 191^2\). None of these sequences of numbers appear in the OEIS as far as I'm aware and I certainly won't be adding them. So nothing of deep mathematical significance in this post, just playing around with powers of numbers and concatenating them. Of course, I've written about Primes Formed By Concatenation quite recently on June 17th 2023.

Tuesday, 9 May 2023

Sums and Concatenations of Cubes and Squares

There's something very obvious about the number associated with my diurnal age today. The number is 27064 and the cubes (27 and 64) stand out clearly. In fact 27064 can be written as a sum of two cubes:$$ \begin{align} 27064 &=27000+64\\&=30^3+4^3 \end{align}$$Unfortunately, the number cannot be written as a concatenation of two cubes because the zero gets in the way. The problem is that 4 cubed has only two digits. However, the cubes of the numbers from 5 to 9 all have three digits and so the zero disappears. This allows us to write the following numbers as both sums and concatenations of two cubes. The symbol | indicates concatenation$$ \begin{align} 27125 =30^3+5^3 = 3^3|5^3\\27216 =30^3+6^3 = 3^3|6^3\\27343 = 30^3+7^3 = 3^3|7^3\\27512 = 30^3+ 8^3 = 3^3|8^3\\27729 = 30^3+9^3=3^3|9^3 \end{align} $$This series of numbers is the last that will occur in my lifetime because the next such sets of numbers will begin with 64125. However, if we were to consider sums of squares and concatenations of squares then I may see these come to pass. Consider the following sets of numbers, some of which occur more than once (permalink).$$ \begin{align} 36100= 114^2+152^2=6^2|10^2\\36121 =20^2+ 189^2=6^2|11^2\\36121 =61^2+ 180^2=6^2|11^2\\36196=40^2+ 186^2=6^2|14^2\\36324 =90^2+ 168^2=6^2|18^2\\36361 =60^2 +181^2=6^2|19^2\\36361=125^2+ 144^2=6^2|19^2\\36441=96^2+ 165^2=6^2|21^2\\36529=48^2+ 185^2=6^2|23^2\\36625=12^2+ 191^2=6^2|25^2\\36625=56^2+ 183^2=6^2|25^2\\36625=65^2+ 180^2=6^2|25^2\\36625=105^2+ 160^2=6^2|25^2\\36676=24^2+190^2=6^2|26^2\\36676=80^2+174^2=6^2|26^2\\36900 =6^2+ 192^2=6^2|30^2\\36900=48^2+ 186^2=6^2|30^2\\36900= 120^2+ 150^2=6^2|30^2 \end{align} $$The first of these numbers (36100) corresponds to Monday, February 3rd, 2048 by which time I'll be almost 88. Maybe I'll make it, maybe I won't.

Friday, 12 August 2022

Skewed Ellipses

My diurnal age today is 26793 days and one of the properties of this number is that it's a member of OEIS A118886:


 A118886

Numbers expressible as \(x^2 + xy + y^2 \), \(0 \leq x \leq y\), in 2 or more ways.      


So in the case of 26793, this means that there are at least two values for \( (x,y) \) such that \(x^2 + xy + y^2 =26793\). It turns out that there are exactly two such values and they are (9, 159) and (93, 96). It's easy to forget that the equation  \(x^2 + xy + y^2 =26793\) is that of an ellipse that is skewed with respect to the \(x\) and \(y\) axes. In other words, it's not your more usual  \(x^2 + y^2 =a^2\) because the \(xy\) term skews it. 

Figure 1 shows the graph along with the two points that have positive integer values: A = (9, 159) and B = (93, 96).


Figure 1

These sorts of ellipses \(x^2 + xy + y^2 =a^2\) have axes of symmetry of \(y=x\) and \(y=-x\) and \( \pm a\) are the intercepts on the \(x\) and \(y\) axes. In the graph shown in Figure 1, the intercepts are \( \pm \sqrt{26793} \approx 163.7 \).

Of course, there are other points on the graph that have integer values but some of these are negative and so are not included in OEIS A118886, Without the condition that \( x \leq y), other points will arise as well. These full range of eight points is shown in Figure 2 and the graph with points added in Figure 3.


Figure 2


Figure 3

Now up to 27000, there are 2043 numbers that qualify for membership in  OEIS A118886 and that represents about 7.6%. However, there are only 69 numbers that are square numbers as well meaning that the intercepts of the \(x\) and \(y\) axes have integer values. These values are:

49, 169, 196, 361, 441, 676, 784, 961, 1225, 1369, 1444, 1521, 1764, 1849, 2401, 2704, 3136, 3249, 3721, 3844, 3969, 4225, 4489, 4900, 5329, 5476, 5776, 5929, 6084, 6241, 7056, 7396, 8281, 8649, 9025, 9409, 9604, 10609, 10816, 11025, 11881, 12321, 12544, 12996, 13689, 14161, 14884, 15376, 15876, 16129, 16641, 16900, 17689, 17956, 19321, 19600, 20449, 21316, 21609, 21904, 22801, 23104, 23716, 24025, 24336, 24649, 24964, 25921, 26569

Take 26569 as an example (see permalink). We have \(26569=159^2\) and the two \( (x,y) \) that satisfy  OEIS A118886 are (0,163) and (75, 112). The full range of ten points are:

(-163, 0), (-163, 163), (-112, -75), (-75, -112), (0, -163), (0, 163), (75, 112), (112, 75), (163, -163) (163, 0)

With these skewed ellipses, if the \(a^2\) in \(x^2 + xy + y^2 =a^2\) is a square number, then there are always another two integer-valued points, \( (a, -a) \) and \( (-a,a) \), compared to non-square numbers. 

Up to 27000, the maximum number of points that satisfy \( 0 \leq x \leq y \) is six. The numbers are 12103, 19747, 22477 and 23569. Using 12103 as an example, the points are (2, 109), (21, 98), (27, 94), (34, 89), (49, 77) and (61, 66). Even extending the range to 100,000, there are no numbers that yield seven points which is not surprising considering the symmetry of the graph. 

There are however, four numbers that yield eight points and these are 53599, 63973, 74347 and 84721. Using, 53599 as an example the eight points are (3, 230), (25, 218), (43, 207), (58, 197), (85, 177), (90, 173), (102, 163) and (122, 145).

Thursday, 28 October 2021

An Interesting Iteration

Having turned 26506 days old today, my attention was drawn to this OEIS sequence:


 A219960

Numbers which do not reach zero under the repeated iteration \(x \rightarrow \lceil \sqrt{x} \, \rceil \times  (\lceil \sqrt{x}\, \rceil ^2 - x) \).


Figure 1 shows that 26506 is the 511th such number and thus the frequency of such numbers is about 1.93%.

Figure 1

The first members of this sequence are as follows:
366, 680, 691, 1026, 1136, 1298, 1323, 1417, 1464, 1583, 1604, 1702, 2079, 2125, 2222, 2223, 2374, 2507, 2604, 2627, 2821, 2844, 2897, 3152, 3157, 3159, 3183, 3210, 3231, 3459, 3697, 3715, 3762, 3802, 3866, 3888, 3936, 3948, 4004, 4111, 4133, 4145, 4231, 4299, ...
Here is a permalink to the algorithm on SageMathCell that will return all members of OEIS A219960 up to and including 26506. 

The OEIS comments include the following conjectures:
  • Conjecture 1: All numbers under the iteration reach 0 or, like the elements of this sequence, reach a finite loop, and none expand indefinitely to infinity. 
  • Conjecture 2: There are an infinite number of such finite loops, though there is often significant distance between them. 
  • Conjecture 3: There are an infinite number of pairs of consecutive integers in this sequence despite being less abundant than in A219303.
OEIS A219303 refers to the iterative process where the ceiling function is replaced by the floor function. So what happens to 26506 under this iteration? Here is the trajectory:
26506, 10269, 13770, 18172, 7155, 5950, 10452, 16171, 27264, 48472, 81549, 70642, 30324, 52675, 51750, 53352, 2079, 1702, 2604, 5200, 9417, 18326, 23120, 44217, 64144, 94488, 115808, 161293, 125022, 104076, 81719, 22022, 26671, 36900, 67357, 63180, 81648, 42328, 22248, 37800, 43875, 47250, 59732, 71785, 10452
As can be seen, after five steps a loop of length 38 is entered with a length of 43 steps overall. Figure 2 shows this trajectory using a log scale for the vertical axis.


Figure 2

Up to 26506, the trajectory of maximum length is associated with the number 25923 that has a trajectory of length 86 and ends in 0:
25923, 52002, 100531, 188574, 283185, 481832, 829135, 716046, 1154461, 1251300, 963459, 849430, 602988, 575757, 245916, 49600, 28767, 22610, 28841, 10030, 17271, 20196, 36179, 57682, 96159, 174782, 326401, 447876, 686080, 962469, 1821610, 1201500, 2094173, 3664888, 4475355, 4445716, 4565985, 1675408, 2094015, 3893672, 5929896, 10231200, 7680799, 8828820, 11781008, 15383273, 26111488, 3127320, 3610529, 6220072, 12357735, 15895836, 1327671, 2003914, 1617072, 1160064, 2177560, 1499616, 1236025, 577128, 358720, 48519, 71162, 33909, 58460, 25168, 17967, 34830, 25993, 40662, 28684, 36720, 27648, 40247, 30954, 3872, 6111, 10270, 13668, 2457, 2150, 2773, 1908, 1232, 2304, 0
Figure 3 shows the trajectory of 25923 using a log scale for the vertical axis.


Figure 3

Figure 4 shows the distribution of trajectory lengths between 1 and 26506. All square numbers immediately become zero under the iteration. Using 25 as an example, we get:

\( \lceil \sqrt{25} \rceil \times ( \lceil \sqrt{25} \, \rceil ^2 - 25) = 5 \times (25 - 25) = 5 \times 0 = 0 \)


Figure 4

So far only the numbers up to and including 26506 have been examined because the algorithm is processor intensive. However, if we search from 26507 to 50000, we find that the record length increases slightly to 91, again ending in 0. Here is the record length attained by 35727:
35727, 70870, 111873, 117920, 143104, 203523, 353012, 602735, 772338, 266337, 492184, 435240, 237600, 265472, 404544, 780325, 999804, 196000, 110307, 193806, 297675, 240786, 144845, 120396, 4511, 7684, 5280, 3577, 1380, 2432, 3400, 4779, 8470, 16647, 32890, 42588, 54027, 61046, 113584, 223080, 306977, 581640, 403627, 552684, 633888, 1052837, 1943084, 211888, 291813, 469588, 691488, 612352, 577071, 402040, 752475, 823732, 664656, 979200, 891000, 128384, 178423, 214038, 153253, 161112, 197784, 107245, 111192, 121576, 78525, 122516, 240435, 317186, 513240, 608733, 959068, 1305360, 1244727, 813564, 36080, 3800, 2728, 4293, 4158, 4355, 66, 135, 108, 143, 12, 16, 0

Here is the permalink for this calculation. Note that the penultimate number in the trajectory is 16 which is a square number (\(4^2\)), just as the penultimate number for the previous record trajectory was 2304, also a square number (\(48^2\)). Clearly, it is only when a square number is reached in the trajectory that a result of zero will arise in the next iteration. However, in the case of over 98% of numbers (at least in the range up to 26506), the trajectory does not terminate at zero but instead enters a loop.

Conjecture 3, included earlier, states that "there are an infinite number of pairs of consecutive integers" so let's investigate this further. In the range up to 26506, the following pairs occur:

  • 2222 2223 
  • 8399 8400 
  • 11457 11458 
  • 12950 12951 
  • 19005 19006 
  • 19847 19848 
  • 22444 22445 
  • 23597 23598 
  • 25089 25090 
  • 25175 25176 
  • 25742 25743 
So eleven pairs in that range shows that pairs of such numbers are not that common and of course there's no way to confirm that there are an infinite number of them.