Problem #251
Ricket Numbers
Rick is working on an important mission but Beth has asked him to look after Morty. Rick doesn't want to be disturbed so he wants to keep Morty busy. He knows how much Morty loves challenges and how much he hates numbers, so he asks Morty to "help" him by counting all the rickety numbers upto 12345678.
A number N is said to be Ricket if and only if it is composite and there exists a way to permute all its divisors (except 1) onto a circle such that the GCD of any two adjacent elements is greater than 1.