The code seems to be working, but so far I have found a couple of tests on which it falls. With 4 it should output 100, with 4939952 10100000010100100010100000000010. Either I messed up with the type of variables somewhere, or the algorithm itself is wrong, but this is from the realm of fiction. Experts, help! Actually, the code itself:
#include <stdio.h> int main() { long a,b, k, x, supercount=0, count=0; unsigned long sumc=0; a=0; b=1; scanf ("%d", &x); k=x; if (x==0){ printf("0"); } for(;x > 0;){ while ((k >= 0) && (a <= xb)){ a=a+b; b=ab; k=k-1; count++; printf("ct=%d\n", count); } x=xa; sumc |= 1 << count-2; b=1; a=0; count=0; } printf("sumc=%lu\n", sumc); int r=sumc; while (r!=0){ r /= 2; supercount++; } int arr[supercount]; for (int q=0; q<supercount; q++){ if (sumc!=0){ arr[q]=sumc%2; sumc/=2; } } for (int i=supercount-1; i>=0; i--){ printf ("%d", arr[i]); } }