The code of the last book

The code of the last book

To code all the books in a library, each one is assigned a three-letter code using the alphabetical order: AAA, AAB, AAC, ..., AAZ, ABA, ABB, etc.

Considering the 26-letter alphabet (without the Ñ) and that the library has 2203 books What is the code of the last book?

Extracted from the page


The idea is that, if we put them in alphabetical order, the first 26 keys only vary in the last letter, the second 26 will repeat the sequence, changing only the central letter, and so on and on until we reach the first one that changes the First letter, which, as Pablo says in the comments, is the key that follows the 26 * 26 = 676. That is, every 676 keys changes the first letter.

Since we have 2203 books, we have to see how many groups of 676 we have used completely, that is, 2203 between 676 gives 3, then we have completely used the keys whose first letter is A, B and C, so the last codes begin with the letter D, and there are 2203 - 676 ​​* 3 = 175 codes that begin with this letter.

Similarly, we must divide 175 by 26 to find out how many letters we have used completely as a second letter, since we have already completely used 6 of the letters as a second letter (A, B, C, D, E and F), by what the last letter we will use as a second letter (and therefore, the second letter present in the last code) will be G. We already know that the last code begins with DG.

And, again, we calculate 175 - 6 * 26 = 19, observing that there will be 19 codes that begin with DG that we will have used, so they will be A, B, C, D, E, F, G, H, I, J , K, L, M, N, O, P, Q, R and S, so the last code used will be the DGS.