JUNE LONG CHALLENGE: Problem code: EOEO
The Tom and Jerry Game!
logic:
For odd case: you just have to find all the values which are even.
For even case: Jerry only wins when Jerry strength is even and tom strength is odd so we have to find only those values of JS which can divided by 2 more times than times who in simpler terms (or in bit terms ) we have to to find all that values which have mores zeroes in the end than TS
CODE:
#include<bits/stdc++.h>
using namespace std;
int main(){
long long t;
cin>>t;
while(t--){
long long tom,jerry,count=0;
cin>>tom;
if(tom%2!=0)cout<<(tom-1)/2<<"\n"; /* if tom strength is odd */
else{ /* if to strength is even */
jerry = __builtin_ctz (tom); /* this gcc function returns no. of zeroes at the end of the number in binary representation */
jerry++; /* for finding all the no. which have more zeroes at the end of the number in binary representation */
jerry=1<<jerry; /* make the smallest no. which have more zeroes */
cout<<tom/jerry<<"\n"; /* and by simply diving you will get the required result */
}
}
return 0;
}
The Tom and Jerry Game!
logic:
For odd case: you just have to find all the values which are even.
For even case: Jerry only wins when Jerry strength is even and tom strength is odd so we have to find only those values of JS which can divided by 2 more times than times who in simpler terms (or in bit terms ) we have to to find all that values which have mores zeroes in the end than TS
CODE:
#include<bits/stdc++.h>
using namespace std;
int main(){
long long t;
cin>>t;
while(t--){
long long tom,jerry,count=0;
cin>>tom;
if(tom%2!=0)cout<<(tom-1)/2<<"\n"; /* if tom strength is odd */
else{ /* if to strength is even */
jerry = __builtin_ctz (tom); /* this gcc function returns no. of zeroes at the end of the number in binary representation */
jerry++; /* for finding all the no. which have more zeroes at the end of the number in binary representation */
jerry=1<<jerry; /* make the smallest no. which have more zeroes */
cout<<tom/jerry<<"\n"; /* and by simply diving you will get the required result */
}
}
return 0;
}
Comments
Post a Comment