Sum or difference of two powers of two Your challenge, should you choose to accept it, is, given an integer K &gt;= 1, find non-negative integers A and B  such that at least one of the two conditions following hold:


K = 2^A + 2^B
K = 2^A - 2^B


If there does not exist such A and B, your program may behave in any fashion. (To clarify, A and B can be equal.)

Test cases

There are often multiple solutions to a number, but here are a few:

K =&gt; A, B
1 =&gt; 1, 0
15 =&gt; 4, 0                      ; 16 - 1 = 15
16 =&gt; 5, 4                      ; 32 - 16 = 16; also 3, 3: 8 + 8 = 16
40 =&gt; 5, 3                      ; 2^5 + 2^3 = 40
264 =&gt; 8, 3
17179867136 =&gt; 34, 11           ; 17179869184 - 2048 = 17179867136 


The last test case, 17179867136, must run in under 10 seconds on any relatively modern machine. This is a code golf, so the shortest program in bytes wins. You may use a full program or a function.
Python 2, 43 bytes



lambda n:[len(bin((n&amp;-n)+k))-3for k in n,0]


Say that n==2^a ± 2^b with a&gt;b. Then, the greatest power-of-2 factor of n is 2^b, and we can find it using the bit-trick 2^b = n&amp;-n. That lets us compute 2^b + n, which equals either 2^a + 2 * 2^b or just 2^a. Either one has the same-length bit-length as a*. So, we output the bit-lengths of n&amp;-n and (n&amp;-n)+n, computed from the lengths of their binary representations. Python 3 is one byte longer for parens in for k in(n,0)].

*Except that 2^a + 2^b with a==b+1 has one longer bit-length, but that's fine because we can interpret that as 2^(a+1)-2^b.