Saturday, 23 August 2025
Fun With Primes and Digit Pairs
Saturday, 1 March 2025
Efficient Sorting Algorithm
Here is a problem that I came across today. Here is the link.
![]() |
Figure 1: Gemini Link |
\( \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.
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. |
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 |
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, ...
- 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.
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:
- Conjecture 3: There are an infinite number of pairs of consecutive integers in this sequence despite being less abundant than in A219303.
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
![]() |
Figure 2 |
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, 0Figure 3 shows the trajectory of 25923 using a log scale for the vertical axis.
![]() |
Figure 3 |
![]() |
Figure 4 |
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







