Cyclic number

A cyclic number is an integer in which cyclic permutations of the digits are successive integer multiples of the number. The most widely known is the six-digit number 142857, whose first six integer multiples are
Details.
To qualify as a cyclic number, it is required that consecutive multiples be cyclic permutations. Thus, the number 076923 would not be considered a cyclic number, because even though all cyclic permutations are multiples, they are not consecutive integer multiples:
The following trivial cases are typically excluded:
If leading zeros are not permitted on numerals, then 142857 is the only cyclic number in decimal, due to the necessary structure given in the next section. Allowing leading zeros, the sequence of cyclic numbers begins:
Relation to repeating decimals.
Cyclic numbers are related to the recurring digital representations of unit fractions. A cyclic number of length "L" is the digital representation of
Conversely, if the digital period of 1/"p" (where "p" is prime) is
then the digits represent a cyclic number.
For example:
Multiples of these fractions exhibit cyclic permutation:
Form of cyclic numbers.
From the relation to unit fractions, it can be shown that cyclic numbers are of the form of the Fermat quotient
where "b" is the number base (10 for decimal), and "p" is a prime that does not divide "b". (Primes "p" that give cyclic numbers in base "b" are called full reptend primes or long primes in base "b").
For example, the case "b" = 10, "p" = 7 gives the cyclic number 142857, and the case "b" = 12, "p" = 5 gives the cyclic number 2497.
Not all values of "p" will yield a cyclic number using this formula; for example, the case "b" = 10, "p" = 13 gives 076923076923, and the case "b" = 12, "p" = 19 gives 076B45076B45076B45. These failed cases will always contain a repetition of digits (possibly several).
The first values of "p" for which this formula produces cyclic numbers in decimal ("b" = 10) are 
For "b" = 12 (duodecimal), these "p"s are 
For "b" = 2 (binary), these "p"s are 
For "b" = 3 (ternary), these "p"s are 
There are no such "p"s in the hexadecimal system.
The known pattern to this sequence comes from algebraic number theory, specifically, this sequence is the set of primes "p" such that "b" is a primitive root modulo "p". A conjecture of Emil Artin is that this sequence contains 37.395..% of the primes (for "b" in ).
Construction of cyclic numbers.
Cyclic numbers can be constructed by the following procedure:
Let "b" be the number base (10 for decimal)<br>
Let "p" be a prime that does not divide "b".<br>
Let "t" = 0.<br>
Let "r" = 1.<br>
Let "n" = 0.<br>
loop:
if "t" = "p" − 1 then "n" is a cyclic number.
This procedure works by computing the digits of 1/"p" in base "b", by long division. "r" is the remainder at each step, and "d" is the digit produced.
The step
serves simply to collect the digits. For computers not capable of expressing very large integers, the digits may be output or collected in another way.
If "t" ever exceeds "p"/2, then the number must be cyclic, without the need to compute the remaining digits.
Other numeric bases.
Using the above technique, cyclic numbers can be found in other numeric bases. (Not all of these follow the second rule (all successive multiples being cyclic permutations) listed in the Special Cases section above) In each of these cases, the digits across half the period add up to the base minus one. Thus for binary, the sum of the bits across half the period is 1; for ternary, it is 2, and so on.
In binary, the sequence of cyclic numbers begins: 
In ternary: 
In quaternary:
In quinary: 
In senary: 
In base 7: 
In octal: 
In nonary:
In base 11: 
In duodecimal: 
In base 13: 
In base 14: 
In base 15: 
In hexadecimal:
In base 17: 
In base 18: 
In base 19: 
In base 20: 
In base 21: 
In base 22: 
In base 23: 
In base 24: 
In base 25:
In ternary ("b" = 3), the case "p" = 2 yields 1 as a cyclic number. While single digits may be considered trivial cases, it may be useful for completeness of the theory to consider them only when they are generated in this way.
It can be shown that no cyclic numbers (other than trivial single digits, i.e. "p" = 2) exist in any numeric base which is a perfect square, that is, base 4, 9, 16, 25, etc.