142857 is the only cyclic number

Is it a cyclic number?

A cyclic number consists of a number of "n" digits which, when multiplied by 1, 2, 3, ... n result in the same digits, but in a different order.

For example, the number 142,857 is a cyclic number because 142,857 × 2 = 285,714, 142,857 × 3 = 428,571, 142,857 × 4 = 571,428, and so on. If you are entering an integer, determine whether it is a cyclic number by returning a logical value if it is and a false value if it is not.

The input can also contain leading zeros, e.g. B. 0344827586206896551724137931

This is because 142857 is the only cyclic decimal number when leading zeros are not allowed for digits.

Since this is code golf, the shortest answer in bytes wins!


thanks to Emigna for storing 3 bytes!


Uses the 05AB1E- Coding. Try it online!

Try it online! (Awaiting quoted input)


Try it online!

Enter numbers as strings.

Application example:

I don't think this algorithm needs any explanation.


Thanks for suggestions: Generic Display Name, Laikoni.

Thanks for the correction: Antony Hatchkins.

EDIT Nope, fails on "33".

Outputs "0" if the number is not cyclical, otherwise "1". Requires the number to be entered as a string.

Application example:


Explanation: The same algorithm as my Haskell submission.

EDIT Nope, fails on "33".

Mathematica, 81 bytes

Try it online!

Input string





We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.

By continuing, you consent to our use of cookies and other tracking technologies and affirm you're at least 16 years old or have consent from a parent or guardian.

You can read details in our Cookie policy and Privacy policy.