Fermat numbers are positive integers that can be expressed as 22x+1 with an integer x.
Let us now define an attribute of a number called "Fermat-ness":
- The Fermat-ness of the number is one less than the length of the chain of powers of two, starting from the base, with powers of two expanded so as to maximize the fermat-ness.
- A number that is not a Fermat number has the Fermat-ness of zero.
So, 17 (=22220+1) has Fermat-ness three.
Given a positive nonzero integer as input, output the Fermat-ness of the number.
- You may take the input in binary, decimal, hexadecimal, as a bignum, or whatever format lets you golf best
- Your solution must be able to process numbers with bit-lengths over 64 whichever representation you use.
- Nonnegative integer powers only.
- Standard loopholes are of course prohibited.
- This is code-golf, so shortest answer wins.
These are in format
input->output. The input is in hexadecimal to save space.
10000000000000000000000000000000000000000000000000000000000000001 -> 2 1000000000000BC00000000000000000000000000000000001000000000000001 ->0 1234567890ABCDEF -> 0 100000000000000000000000000000001 -> 1 5 -> 2 11 -> 3 10001 -> 4 101 -> 1
The same in decimal:
115792089237316195423570985008687907853269984665640564039457584007913129639937 -> 2 115792089237316497527923305698859709742143344804209838213621568094470773145601 -> 0 1311768467294899695 -> 0 340282366920938463463374607431768211457 -> 1 5 ->2 17 -> 3 65537 -> 4 257 -> 1
Thanks to geokavel for invaluable input in the sandbox.