Sometimes, when I'm idly trying to factor whatever number pops up in front of me¹, after a while I realize it's easier than I thought. Take 2156
for example: it eventually occurs to me that both 21
and 56
are multiples of 7
, and so certainly 2156 = 21 x 100 + 56
is also a multiple of 7
.
Your task is to write some code that identifies numbers that are easier to factor because of a coincidence of this sort.
More precisely:
Write a program or function that takes a positive integer n
as input, and returns a truthy value if there exists a divisor d
(greater than 1
) such that n
can be chopped in two to yield two positive integers, each of which is a multiple of d
; return a falsy value if not.
- "Chopped in two" means what you think: the usual base-10 representation of
n
partitioned at some point into a front half and a back half to yield two other base-10 integers. It's okay if the second integer has a leading zero (but note that it must be a positive integer, so splitting1230
into123
and0
is not valid). - The truthy and falsy values can depend on the input. For example, if any nonzero integer is truthy in your language of choice, then you are welcome to return the divisor
d
or one of the "pieces" ofn
(orn
itself for that matter). - For example, any even number with at least two digits in the set
{2, 4, 6, 8}
will yield a truthy value: just split it after the first even digit. Also for example, any prime numbern
will yield a falsy value, as will any one-digit number. - Note that it suffices to consider prime divisors
d
. - You may assume the input is valid (that is, a positive integer).
This is code-golf, so the shortest code in bytes wins. But solutions in all languages are welcome, so we can strive for the shortest code in each language, not just the shortest code overall.
Test cases
(You only have to output a truthy or falsy value; the annotations below are just by way of explanation.) Some inputs that yield truthy values are:
39 (3 divides both 3 and 9)
64 (2 divides both 6 and 4)
497 (7 divides both 49 and 7)
990 (splitting into 99 and 0 is invalid; but 9 divides both 9 and 90)
2233 (11 divides both 22 and 33)
9156 (3 divides both 9 and 156; or, 7 divides both 91 and 56)
11791 (13 divides both 117 and 91)
91015 (5 divides both 910 and 15)
1912496621 (23 divides both 1912496 and 621; some splittings are multiples of 7 as well)
9372679892 (2473 divides both 937267 and 9892; some splittings are multiples of 2 as well)
Some inputs that yield falsy values are:
52
61
130 (note that 13 and 0 is not a valid splitting)
691
899
2397
9029
26315
77300 (neither 7730 and 0 nor 773 and 00 are valid splittings)
2242593803
¹ yes I really do this