ITGUY10 - Editorial

Problem: https://www.codechef.com/PBK02020/problems/ITGUY10

DIFFICULTY:

EASY.

PROBLEM:

Chef gives an integer KK in the input. If the given number is beautiful binary number, print it, Else find its previous beautiful binary number. A beautiful binary number is a number whose binary representation does not contain any consecutive 1s.

Note: 1 is also a beautiful binary number.

Program:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int arr[100001];
for(int i=1;i<100001;i++){
int n;
n=i;
while(n & (n << 1))
n–;
arr[i]=n;
}
ll t;
cin>>t;
while(t–){
int k;
cin>>k;
cout<<arr[k]<<"\n";
}
return 0;
}

1 Like