Tom and jerry unique solution

https://codingallinone.blogspot.com/
one of the unique solution for tom and jerry problem.

1 Like

https://youtu.be/QKZV6xJjpV8
One line code

I have also implemented it in the same manner have a look at https://www.codechef.com/viewsolution/33895759

my solution can also be implement in one line… but for beginners, this way is more explanatory. and this solution makes people to think on bit level… bit operations are way more faster .

yeah you use same manner … but the code is not DRY. Look at my code… no extra conditions.

isn’t that standaard?

“bit operations are much more fast”
Here you go (AC).

#include <bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		long long ts;
		cin >> ts;
		while (!(ts & 1)) ts >>= 1;
		cout << (ts >> 1) << '\n';
	}
}

Your solution was very hard to understand. I made a new one only with bit operations :wink: