Teaser 2527: [Number prefixes]
From The Sunday Times, 27th February 2011 [link] [link]
Without repeating a digit I wrote down two five-figure numbers. For the first of these, its first two digits form a number divisible by two, its first three digits form a number divisible by three, and likewise for four and five. For the second number, looking again at the numbers formed by the first few digits, those of prime length are prime and the one of length four is a square. Furthermore the sum of the digits of the difference between the two numbers is itself a digit. Without doing much division you should now be able to answer the question:
What are the two five-figure numbers?
This puzzle was originally published with no title.
[teaser2527]
Jim Randell 11:37 am on 24 May 2021 Permalink |
Here is a solution using the [[
SubstitutedExpression]] solver from the enigma.py library.The following run file executes in 122ms.
Run: [ @replit ]
Solution: The numbers are: 52840 and 73961.
LikeLike
Frits 12:07 pm on 26 May 2021 Permalink |
from itertools import compress from math import isqrt # return true if an integer <n> is a perfect square def is_square(n): if n % 144 not in {0, 1, 4, 9, 16, 25, 36, 49, 52, 64, 73, 81, 97, 100, 112, 121}: return False return isqrt(n) ** 2 == n def primesbelow(n): # rwh_primes1v2(n): """ Returns a list of primes < n for n > 2 """ sieve = bytearray([True]) * (n // 2 + 1) for i in range(1, int(n ** 0.5) // 2 + 1): if sieve[i]: sieve[2*i*(i+1)::2*i+1] = \ bytearray((n // 2 - 2 * i * (i + 1)) // (2 * i + 1) + 1) return [2, *compress(range(3, n, 2), sieve[1:])] digits = "0123456789" P = primesbelow(100000) odds = ["1", "3", "5", "7", "9"] second = [] # determine second number FGHIJ for FG in [str(x) for x in P if 11 < x < 100]: (F, G) = (FG[0], FG[1]) for H in [x for x in odds if x not in {F, G}]: if int(FG + H) not in P: continue for I in [x for x in digits if x not in {F, G, H}]: if not is_square(int(FG + H + I)): continue for J in [x for x in odds if x not in {F, G, H, I}]: if int(FG + H + I + J) not in P: continue second.append(FG + H + I + J) for FGHIJ in second: remaining = "".join(x for x in digits if x not in FGHIJ) # determine first number ABCDE for E in [x for x in remaining if x in "05"]: for B in [x for x in remaining if x not in {E} and x in "02468"]: for A in [x for x in remaining if x not in {B, E} and x != "0"]: for C in [x for x in remaining if x not in {A, B, E}]: if int(A + B + C) % 3: continue for D in [x for x in remaining if x not in {A, B, C, E}]: if int(C + D) % 4: continue ABCDE = int(A + B + C + D + E) # the sum of the digits of the difference between the two numbers # is itself a digit if sum(int(x) for x in str(abs(int(FGHIJ) - ABCDE))) > 9: continue print(f"the two five-figure numbers are: {ABCDE} and {FGHIJ}")LikeLike
GeoffR 4:20 pm on 26 May 2021 Permalink |
from itertools import permutations from enigma import is_prime sq4 = [x ** 2 for x in range(32, 100)] # Find digits for first 5-digit number for P1 in permutations('1234567890', 5): A, B, C, D, E = P1 if A == '0': continue # two,three, four and five digit numbers # are divisible by two, three, four and five AB = int(A + B) if AB % 2 != 0: continue ABC = int(A + B + C) if ABC % 3 != 0: continue ABCD = int(A + B + C + D) if ABCD % 4 != 0: continue ABCDE = int(A + B + C + D + E) if ABCDE % 5 != 0: continue # Find digits for second 5-digit number Q1 = set('1234567890').difference([A, B, C, D, E]) for P2 in permutations(Q1): F, G, H, I, J = P2 if F == '0': continue # two, three and five digit numbers are prime FG = int(F + G) if not is_prime(FG): continue FGH = int(F + G + H) if not is_prime(FGH): continue # four digit number is square FGHI = int(F + G + H + I) if FGHI not in sq4: continue FGHIJ = int(F + G + H + I + J) if not is_prime(FGHIJ): continue # the sum of the digits in the difference between # the two numbers is a digit dd = sum(int(x) for x in str(abs(ABCDE - FGHIJ))) if not dd < 10: continue print(f"Two five-figure numbers are {ABCDE} and {FGHIJ}.") # Two five-figure numbers are 52840 and 73961.LikeLike
John Crabtree 6:46 pm on 26 May 2021 Permalink |
As the 3rd digit of N2 is odd, the 4th digit is 6.
(10a + 4)^2 = 100a(a + 1) – 20a + 16, with 2nd digit odd for 0 < a < 6
(10a + 6)^2 = 100a(a + 1) + 20a + 36, with 2nd digit odd for 3 < a N2 but the sum of the digits of the difference (SDD) cannot be 2
86^2 = 7396, N2 = 73961, N2 > N1, SDD = 7, N1 = 52840 (not 42850)
Using a prime factor calculator, 739 and 73961 are all prime.
LikeLike
Frits 10:06 am on 27 May 2021 Permalink |
Tens place digit of a perfect square is always even except number ending with 6: see [ https://math.stackexchange.com/questions/2090355/tens-place-digit-of-a-perfect-square-is-always-even-except-no-ending-with-6/2090362 ].
LikeLike