ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1081. Binary Lexicographic Sequence

help me
Posted by hhh 12 Mar 2009 16:10
#include <iostream>
using namespace std;
long long n,k,a[45],i=0,b[50],j,t=0,r=0,z,c[50];
int main()
{
cin>>n>>k;  a[0]=1; a[1]=2;   t=n;
for(i=2; i<=n; i++) a[i]=a[i-1]+a[i-2];
if(k>a[n]) { z=-1; cout<<z;  return 0; }
else{  b[1]=b[2]=0; b[3]=1; b[4]=2;
for(i=5; i<=n; i++) b[i]=2*b[i-1]+1;
 while(a[i]<=k) { i++; j=i; }
for(i=1; i<=j; i++) z+=b[i];
r=k+z-1;
while(r!=0) { c[t]=r%2; r/=2; t--; }
for(i=1; i<=n-t; i++) c[i]=0;
for(i=1; i<=n; i++)  cout<<c[i];
return 0; }}

wa#2