Find the binary period We know that not all fractions have a terminating binary representation.  However every fraction can be written as a leading portion followed by a repeating portion.  For example \$1/3\$ starts with \$0.\$ and then just repeats \$01\$ endlessly.  This corresponds to the bar notation taught in primary school.  For example

$$
1/3 = 0.\overline{01}
$$

Where the portion with the bar is the repeating section.

For numbers with a terminating representation, (e.g. \$1/2 = 0.1\$) the repeating section is just \$0\$, since there are endless implicit zeros at the end of a terminating representation.

We will call the minimum1 length of the repeating section the binary period of the fraction.

Your task is to write a program or function which takes a positive integer \$n\$ as input and outputs the binary period of \$1/n\$.

This is code-golf so answers will be scored in bytes with fewer bytes being better.

OEIS A007733



1: We say minimum because if you duplicate a section again it keeps a valid representation. (e.g. \$0.\overline{01} = 0.\overline{0101}\$)
Jelly, 9 bytes

2*Ɱ%µẠȧQL


A monadic Link accepting a positive integer, n, which yields a positive integer, the period.

Try it online! Or see the test-suite.

How?

2*Ɱ%µẠȧQL - Link: integer, n
2         - literal two
  Ɱ       - map across [1..n]
 *        - exponentiate -&gt; [1,2,4,8,...,2^n]
   %      - modulo n -&gt; [1%n,2%n,4%n,8%n,...,2^n%n]
    µ     - start a new monadic chain - call that X
     Ạ    - all (X)? -&gt; 0 if we reach zero, else 1 - i.e. 0 if n is a power of 2
       Q  - de-duplicate (X) -&gt; the repeating 2^k%n values 
      ȧ   - logical AND -&gt; 0 if n is a power of 2 else Q(X)
        L - length (0 has a length of 1 (after an implicit make_digits))