n / ((n & -n) << 1) //n: tom's strength

n / ((n & -n) << 1) //n: tom's strength

#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--){
long long n;
cin >> n;
while(n%2==0){
n/=2;
}
cout << n/2 << '\n';
}
}
https://codingallinone.blogspot.com/
check this solution, this solution has unique implementation and thinking you definitely going to learn something
June long challenge editorial beginner friendly video explanation with animation and code
Delicious cake (CONTAIN) : Codechef June Long Challenge||The Delicious Cake(CONTAIN) - YouTube
Tom and jerry (EOEO) : CodeChef June Long Challenge||The Tom and Jerry Game!||EOEO - YouTube
Even matrix (EVENM) : CodeChef June Long Challenge||Even Matrix|| EVENM - YouTube
yes
#include<bits/stdc++.h>
using namespace std;
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--)
{
long long int a;
cin>>a;
if(a%2==1)
{
cout<<(a-1)/2<<"\n";
}
else
{
long long int ans =a;
long long int x=0;
while(a%2==0)
{
x++;
a=a/2;
}
long long int y = pow(2,x+1);
cout<<(int)ans/y<<"\n";
}
}
}
whats wrong with my code seems like i have done it like editorial during contest time only subtask 1 passed subtask 2 failed… please explain someone
Hi!
After reading your solution I got to know that I misunderstood the question, however even after reading the question now once again I still can’t seem to find why my understanding is wrong. Please guide me where I went wrong with respect to the question statement.
Here’s my pseudo code:
START
Input test case, and for each test case repeat the following process:
Input TS
If TS is odd, answer is TS//2
If TS is even, JS can have all the even values from 2 to TS, for each combination of TS and JS do the following:
- Divide both TS and JS by 2 till one of them becomes odd,
- If TS becomes odd first then increment a counter (ctr ++)
- If JS becomes odd first then do nothing.
Print ctr
END
Thanks in advance!
so stupid of me. i did typecasted to int , didnt have to do any typecasting
it should have been long long
This Question Gave me AC in the first attempt, i was surprised chef and ice cream was kept before this question
I know I am doing a stupid mistake or something but I am unable to find it so can someone help me.
I am only getting a partial.
t = int(input())
for i in range (0 , t):
ts = int(input())
temp = ts
count = 0
while ts % 2 != 1:
ts = ts / 2
count = count + 1
m = 2 ** (count + 1)
print(int(temp/m))
please format your code from now on
Also, read the question carefully…divide TS by 2 till it is odd and JS can have all values such that JS divided by same number (2**n) will be even
copy pasted from vscode it looks formatted there used preformatted text here several times in edit didnt work… how to format it correctly?
UPD: done formatting
I figured it and did it like this, look like a noob’s solution but go correct answer 
Let,
N = number of JS choices leading Jerry to win,
Start
TS = 20
JS = 2 4 6 8 10 12 14 16 18 20 - excluding odd nums leading to loss
proceed to next turn with above JS
divide TS by 2 and all Possible JS choices by 2
TS/2 = 10
JS/2 = 1 2 3 4 5 6 7 8 9 10
Valid JS = 2 4 6 8 10 - excluding odd nums leading to loss(N=N/2)
proceed to next turn with above JS
divide TS by 2 and all Possible JS choices by 2
TS/2 = 5
JS/2 = 1 2 3 4 5
Winning entries = 2 4 (from choices 6 and 8) (N = (N-1)/2)
// for last turn we do (N-1)/2 instead of N/2 due to inclusion of TS as upper bound in choice of JS
Code:-
count =(found by counting trailing 0’s in TS’s binary rep)
ie How many times I have to divide this number to get an odd num so jerry wins with an even num on that turn
long possibleJSChoices =(TS)/2;//all even nums between 1 and TS so that game proceeds
long N = possibleJSChoices
for(int i = 0 ; i < count;i++)
{
if(i==count-1)
N = (N-1)/2;
else
N = (N)/2;
}
System.out.println(""+N);
I had an approach on similar lines.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int T, TS, result, ts, count, divisor, i;
cin >> T;
for (i = 0;i<T;i++){
cin >> TS;
if (TS % 2 != 0){
result = TS/2;
cout << result<<'\n';
}
else{
ts = TS;
count = 0;
while (ts % 2 == 0){
ts = ts/2;
count ++;
}
count++;
divisor = pow(2,count);
result = TS/divisor;
cout << result<<'\n';
}
}
}
Can anyone help me with this. Got WA for subtask-2 for my solution:
https://www.codechef.com/viewsolution/34236993
thanks for formatting it doe 
yeah the logic is sound…
what was the result?
i tried running your code on online IDE but its giving EOF error dunno why
my approach:
t = int(input())
for i in range(t):
…ts = int(input())
…if ts % 2 == 0:
…while(ts % 2 == 0):
… ts = ts // 2
…j = (ts - 1) // 2
…else:
…j = (ts - 1) // 2
print(j)