Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

BINTREE april challenge..Can anyone tell me what's wrong with this approach??

$
0
0
 #include<iostream>
 #include<cmath>
 #include<math.h>
 using namespace std;
 int main()
 {
 unsigned long long int i,j,pos1,pos2,num1,num2,cases;
 cin>>cases;
 while(cases--)
 {
 cin>>i>>j;
 pos1 = log(i)/log(2) + 1;
 pos2 = log(j)/log(2) + 1;
 num1 = pos1;
 num2 = pos2;
 if(pos1>pos2)
 {
 while(pos1!=pos2)
 {
 i = i/2;
 pos1--;
 }
 }
 else if(pos2>pos1)
 {
 while(pos2!=pos1)
 {
 j = j/2;
 pos2--;
 }
 }
 if(i==j)
 cout<<(num1+num2-2*pos1)<<endl;
 else
 {
 while(i!=j)
 {
 i=i/2;
 j=j/2;
 pos1--;
 }
 cout<<(num1+num2-2*pos1)<<endl;
 }
 }
 return 0;     
 }

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>