1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# Brian's number base conversion function def nbr_to_base(num, base): dgts = [] while num: num, r = divmod(num, base) dgts.append(r) return ''.join(str(x) for x in reversed(dgts)) for n in range(50, 100): N4 = n * n N5 = 4 * N4 if nbr_to_base(N4, 7) == nbr_to_base(N5, 10): print(f"Four Digit Number is {N4}") print(f"Five Digit Number is {N5}") print(f"Associated squares are {n}^2 and {2*n}^2") |

it gives 4n², if it is interpreted as a base 7 number it gives n².

For example if n=94, then n² = 8836 and 4n² = 35344.

If we take the 5 digit string “35344” and interpret it as base 10 we get

35344 (which is 4n²), and if we interpret it as base 7 we get 9097.

Which isn’t n², but it’s not that far off.

At no point do we need to consider the base 7 representation of 35344

(which would be “205021”).

The teaser says “… if the five-digit number was treated as being to base 7 …”.

This surely refers to \(4.n^2\), not \(n^2\)?

I do not understand why your range for i is (100, 121) ie checking values of h only up to 14400.

Just considering h as 4 x (a 4 digit square) gives highest possible value 4 x 9801 = 39204 which seems to demand range (100, 199).

Obviously considering base 7 gives max h = 36666 (and so 36100) but this still needs (100, 191).

]]>But, it’s the representation of n² in base 7 that has 5 digits, not the representation of (2n)².

]]>