Skip to content

Instantly share code, notes, and snippets.

@TheoKlein
Created July 17, 2016 09:00
Show Gist options
  • Select an option

  • Save TheoKlein/0d1e23bce7b5e1b7bad484926b6e302d to your computer and use it in GitHub Desktop.

Select an option

Save TheoKlein/0d1e23bce7b5e1b7bad484926b6e302d to your computer and use it in GitHub Desktop.
ZeroJudge a134
#include <iostream>
#include <cmath>
using namespace std;
int fib( int * );
int main() {
int n;
cin >> n;
while( n-- > 0 ){
int num;
cin >> num;
cout << num << " = ";
int length = fib(&num) , result[length + 1];
for(int i = 0 ; i < length ; ++i)
result[i] = 0;
result[length] = 1;
while(num > 0)
result[fib(&num)] = 1;
for(int i = length; i >= 0 ; --i)
cout << result[i];
cout << " (fib)" << endl;
}
}
int fib( int *num ){
int fib[50] = { 0 } , i = 2;
fib[0] = 0 , fib[1] = 1 , fib[2] = 1;
while(fib[i] <= *num){
fib[i + 1] = fib[i] + fib[i - 1];
i++;
}
*num -= fib[i - 1];
return i - 3;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment