4 ms·
My solution was similar, represent. First we observe x is between 20^3=8e3 and 30^3=27e3. Then note that the least significant (singles) digit of x^3 is so
by bohadi 4y ago
My solution was similar, represent.
First we observe x is between 20^3=8e3 and 30^3=27e3.
Then note that the least significant (singles) digit of x^3 is solely determined by the singles digit of x [only holds in the integers].
Luckily we had cached that the pattern for cubes is 123456789 -> 187456329
Finally x^3 = 19,683 ends in 3 therefore x = 27 we are done.
------
It turns out there is a unique mapping for the first digit of x^n, following one of four patterns:
n mod 4 = 1 123456789 -> 123456789
n mod 4 = 2 -> 149656941
n mod 4 = 3 -> 187456329
n mod 4 = 0 -> 161656161
So this trick would not always be as useful, where the mapping is not surjective for squares, fourth powers -- all the even powers. I imagine there is a nice visual geometric explanation why those mappings take their symmetric pattern.
You may ask yourself, is there also a rule for the larger place digits of x^3, x^n? Yes, we naturally observe that the 10s digit of x^n is similarly wholly determined by the 10s and 1s digits of x. So now we want n maps on [0,9]x[0,9] to [0,9].
The python snippet may help to explore this:
where the row 3, 25th digit shows that when x ends in 25, x cubed has 10s digit 2
>>> print(*zip(range(50), [''.join([str(x**i).zfill(2)[-2:-1] for x in range(100)]) for i in range(50)]), sep='\n')
(0, '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')
(1, '0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999')
(2, '0000123468024692582604827272840628529642086432100000001234680246925826048272728406285296420864321000')
(3, '0002621412032947913506462278580963075571028082329405076719170824429630014127735304680250760785873799')
(4, '0018529096043612327208547274580272321634069092581000185290960436123272085472745802723216340690925810')
(5, '0034227064053927756900342270640539277569003422706405392775690034227064053927756900342270640539277569')
(6, '0062925444068032162802087278020826123086044452926000629254440680321628020872780208261230860444529260')
(7, '0028823456070107573304842270100167479397084062167405238739510206025238098927751506624298920345671179')
...
(19, '0086429478094787353708082276960769671755062002581405814799730442823032030327719102646212500125075319')
(20, '0070727070007072707000707270700070727070007072707000707270700070727070007072707000707270700070727070')
(21, '0050025000011167116102722272220333873383049442944405550755050616621666077727772708388238880999479949')
(22, '0000123468024692582604827272840628529642086432100000001234680246925826048272728406285296420864321000')
(23, '0002621412032947913506462278580963075571028082329405076719170824429630014127735304680250760785873799')
(24, '0018529096043612327208547274580272321634069092581000185290960436123272085472745802723216340690925810')
...
(35, '0060227434056527793900602274340565277939006022743405652779390060227434056527793900602274340565277939')
(36, '0032925054061432187802967276920878123416045052923000329250540614321878029672769208781234160450529230')
(37, '0076823046079307576304102274800137479107085462182405718735410298025268091527798506324296020359671329')
(38, '0048321482080252902406667276660420925208028412384000483214820802529024066672766604209252080284123840')
(39, '0086429478094787353708082276960769671755062002581405814799730442823032030327719102646212500125075319')
(40, '0070727070007072707000707270700070727070007072707000707270700070727070007072707000707270700070727070')
(41, '0050025000011167116102722272220333873383049442944405550755050616621666077727772708388238880999479949')
(42, '0000123468024692582604827272840628529642086432100000001234680246925826048272728406285296420864321000')
(43, '0002621412032947913506462278580963075571028082329405076719170824429630014127735304680250760785873799')
...
-----
Apologies for the wall of text but the output is included here to show the periodicity is 20 in the 10s digit for powers of n.
What do you think the periodicity in the 100s digit is?
Okay let's use our cache to just lookup the least two digits of say, 41679296 ^ 35 (without doing any real compute):
1s digit
35 mod 4 = 3
187456329 index 6 -> 6
10s digit
(35, '0060227434056527793900602274340565277939006022743405652779390060227434056527793900602274340565277939')
index ------96 -> 7
The last two digits of 41679296 ^ 35 = 497981393104388234083687472206165994017494365065741791800324926291638211001469403054062791593737655590988883756006534609416313532750908441977019034732014717649617778735038244085515193249673259731575280032440237649262981884959117005449913087392615145373869733708824576 are indeed 76, cool