I have given the problem link below. What I can't figure out is how to optimize this code so that I can make this program run within 1 sec and don't get a TLE.
Problem link: https://codeforces.com/contest/1527/problem/A
My code:
#include <bits/stdc++.h>
using namespace std;
int rett(int l, int sum)
{
sum = l & (l - 1);
if (sum != 0) {
rett(l - 1, sum);
}
else {
cout << (l - 1) << endl;
}
}
int main()
{
int t, f = 0;
int x;
cin >> t;
int i = 0;
while (i < t) {
cin >> x;
int sum = 0;
rett(x, sum);
i++;
}
return 0;
}