10
0
inspired by this chat conversation
A satisfying number is a number whose decimal representation is of the form abx
, with the following properties:
x
is the longest trailing repeating suffix, or the last digit if there is no repetition at the end (123333
->3333
,545656
->5656
,123
->3
)b
is the single digit prior tox
(123333
->2
,55545656
->4
)a
is the remaining prefix (123333
->1
,55545656
->555
)a == c**b
(**
denotes exponentation), wherec
is the number of repetitions of the smallest repeating portion ofx
(1623333
->4
(3 3 3 3
, not33 33
))
For example, 8300
is a satisfying number with a = 8
, b = 3
, c = 2
, and x = 00
. 24651
is not a satisfying number, because x = 1
, b = 5
, a = 246
, and there is no integer c
that satisfies c^5 = 246
. 1222
is also not a satisfying number, because with x = 222
and b = 1
, there are no remaining digits for a
.
Given a positive integer n >= 100
, output whether or not n
is a satisfying number.
Examples
8300: True (a=8, b=3, c=2, x=00)
24651: False
1222: False
92555: True (a=9, b=2, c=3, x=555)
64633: True (a=64, b=6, c=2, x=33)
512944: True (a=512, b=9, c=2, x=44)
123: True (a=1, b=2, c=1, x=3)
822809: False
376664: False
723799: False
1234: False
34330000000: True (a=343, b=3, c=7, x=0000000)
92313131: True (a=9, b=2, c=3, x=313131)
16424442444: True (a=16, b=4, c=2, x=24442444)
Sandbox – Mego – 2017-12-22T19:00:26.203
2
Also somewhat related.
– Mr. Xcoder – 2017-12-22T19:12:31.580With
8333
isx,c,b,a=33,2,3,8
and therefore satisfying? – Jonathan Allan – 2017-12-22T20:18:05.367@JonathanAllan No, because
x
is greedy. – Mego – 2017-12-22T20:18:40.823OK, thanks, so
a
is undefined here? (hence not satisfactory?) – Jonathan Allan – 2017-12-22T20:19:29.5031@JonathanAllan Exactly. A number having at least two digits before a repeating portion is a necessary condition for being satisfying. – Mego – 2017-12-22T20:21:23.530
Huh. I’d thought a number like 477223 is satisfying. – Stan Strum – 2017-12-22T20:28:13.317
Must the number of repetitions be chosen as large as possible? For example, in
1645555
, can we choose55
as the repeated string so thatx = 55 55
andc = 2
? – Zgarb – 2017-12-23T10:19:42.493Another test case:
16424442444
. – Zgarb – 2017-12-23T11:19:08.043@Zgarb "
x
is the longest trailing repeating suffix" - as explained in a previous comment,x
is greedy. – Mego – 2017-12-23T12:22:39.163@Mego But what about c? If x = 5555, c could be 2 (two repetitions of 55) or 4 (four repetitions of 5). – Dennis – 2017-12-23T14:57:43.480
@Dennis I see the confusion now. I'll clarify. – Mego – 2017-12-23T15:16:13.900
Does longest repeating suffix refer to longest in terms of what is repeated, the number of times it is repeated, the length of all of the repetitions, or does it not matter? So is the longest repeating suffix of
133333
equal to3 3 3 3 3
or33 33
? – Daniel – 2017-12-26T04:32:07.227@Dopapp Longest repeating suffix means the longest string at the end of the original string that has repetition. The grouping does not matter for the purpose of determining the longest repeating suffix. – Mego – 2017-12-27T02:02:29.387