Sunday Times Teaser 2854 – Power Surge
by Andrew Skidmore
Published June 4 2017 (link)
I recently checked my energy bills. I noticed that the account numbers for my electricity and gas are two different six-figure numbers, and that one is a multiple of the other. The electricity account number is a perfect cube and the sum of its digits is a perfect square. The gas account number is a perfect square (and, as it happens, the sum of its digits is a perfect cube!).
What is the gas account number?
2 Comments
Leave one →
-
Brian Gladman permalink12345678910111213141516171819202122232425# return the <n>'th root of integer <m> if it is an integerdef is_power(m, n):rt = round(m ** (1 / n))return rt if rt ** n == m else 0# return the <n>'th root of the sum of the digits of <m> if it is an integersum_digits_is_power = lambda m, n: is_power(sum(int(x) for x in str(m)), n)# the electricity account number is a six digit cubefor i in range(47, 100):e = i ** 3# ... whose sum of digits is a squareif sum_digits_is_power(e, 2):# list possible gas account numbers (six digit multiples# and divisors of the electricity account number)gl = ([e * m for m in range(2, 10) if e * m < 1000000]+ [e // m for m in range(2, 10) if e % m == 0])# the gas account number is a squarefor g in gl:rt = is_power(g, 2)# ... whose sum of digits is a cubeif rt and sum_digits_is_power(g, 3):print(f'gas: {g} ({rt}^2); electricity: {e} ({i}^3).')
-
geoffrounce permalink12345678910111213141516171819202122232425262728def is_cube(n):c = int(n ** (1 / 3) + 0.5)return (c ** 3 == n)def is_sq(n):c = int(n ** (1 / 2) + 0.5)return (c ** 2 == n)gas_sq = [x * x for x in range(316, 1000)]elec_cb = [x * x * x for x in range (47, 100)]gas_list = []elec_list = []for e in elec_cb:for g in gas_sq:if e % g == 0 and e != g:gas_list += [g]elec_list += [e]for g in gas_list:sum_g = sum(int(x) for x in str(g))for e in elec_list:sum_e = sum(int(x) for x in str(e))if is_cube(sum_g) and is_sq(sum_e) and e % g == 0:print('Gas account no. = {}, Electricity account no. = {}'.format (g, e))