n bits do not contain leading 0 without a number of consecutive 1 total fib (n), FIB (n) is the Fibonacci sequence.
So you can preprocess the FIB prefix and look for the nth number is the K-digit number, and then recursively calculate how many bits of the k-digit it is.
For example, to find a 11th number, find it is a 5-digit number, so the highest bit is a 1, and then it is the 4th number in the 5-digit number.
This is to find the third number, because the following number allows leading zeros, the third number is 100, so the 5th bit is 1, the 4th bit is 0, the back three bits is 100,
The answer is 10100.
It's a bit verbose, but it's easy to understand how to simulate it on paper.
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 6typedefLong LongLL;7 8 Const intMAXF =90000000+5;9 Const intMAXN = -;Ten One LL FIB[MAXN], SUM[MAXN]; A intans[ -], p =0; - - voidFintN) the { - if(n = =0)return; - intdigits = Lower_bound (sum+1, Sum+p, N)-sum; -ans[digits-1] =1; +N-= sum[digits-1]; -n--; + f (n); A } at - intMain () - { - intT, N; scanf"%d", &T); - -fib[1] = fib[2] =1; in for(P =3; fib[p-1] < MAXF; p++) Fib[p] = fib[p-1] + fib[p-2]; -sum[1] = fib[1]; to for(inti =2; I < P; i++) Sum[i] = sum[i-1] +Fib[i]; + - while(t--) the { *scanf"%d", &n); $memset (ans,0,sizeof(ans));Panax Notoginseng intD = Lower_bound (sum+1, Sum+p, N)-sum; - f (n); the for(inti = d1; I >=0; i--) printf ("%d", Ans[i]); +printf"\ n"); A } the + return 0; -}
code June
LA 3357 (recursive search rule) pinary