Consider
x = 3168 and
y = 7A2B4C54995D458E1F9G6H3I17862, where
ABCDEFGHI represents some permutation of the digits 1, 2, 3, 4, 5, 6, 7, 8, 9.
Determine the total number of such
permutations such that the remainder of y upon division by x is exactly 2022.
Cute!
The script was built up to the next to last line shown:
ys='70204054995045801090603017862'
y=sym(ys);
x=3168;
baseMod=mod(y,x)
ix=strfind(ys,'0')
positions=length(ys)-ix
vals=powermod(sym(10),positions,x)
shouldBe2022=baseMod+mod((sum([1:9].*vals)),x)
when I added the shouldBe2022= line at the end, after seeing the results of the preceding lines.
ys =
'70204054995045801090603017862'
baseMod =
582
ix =
2 4 6 12 16 18 20 22 24
positions =
27 25 23 17 13 11 9 7 5
vals =
[1792, 1792, 1792, 1792, 1792, 1792, 1792, 1792, 1792]
shouldBe2022 =
2022
meaning that
If the lettered positions were all zero, the modular value of the long number would be 582.
The positions (leftmost is 1) of the letters are given in the value of the ix vector (array).
The decimal power (power of 10) value of the positions is shown in the positions vector.
The modular value of 10 raised to that power value is given by vals. And, surprise, they are all the same: 1792.
Adding 582 to the sum of the digits 1 through 9 times 1792 does indeed give 2022 mod x.
Therefore each of the 9! = 362880 permutations gives the desired number.
|
Posted by Charlie
on 2023-07-06 07:11:45 |