Created
August 19, 2017 02:51
-
-
Save fazd/14914677adc2d0a7cec4c2fd8a84cbd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<stdio.h> | |
#include<stdlib.h> | |
#include<math.h> | |
using namespace std; | |
int main () | |
{ | |
int n,x,pos=1,prod,temp,var,j=2; | |
cout<<"n= "; | |
cin>>n; | |
n=n-1; | |
cout<<"x="; | |
cin>>x; | |
if(x%2==1){ | |
pos=1; | |
int i=1; | |
prod= pow(2,n); | |
int k=pow(2,i); | |
while(prod/2>k){ | |
cout<<"KKKKKK="<<k<<endl; | |
var=pow(2,n-j); | |
temp = x/k; | |
cout<<"var="<<var<<endl; | |
cout<<"temp="<<temp<<endl; | |
if(temp%2==0){ | |
pos=pos+0; | |
} | |
else{ | |
pos=pos+var; | |
} | |
cout<<"pos="<<pos<<endl; | |
k=k*2; | |
j++; | |
} | |
int otra= pow(2,n-1); | |
cout<<"otra="<<otra<<endl; | |
if(x>otra && !n==0){ | |
pos=pos+1; | |
} | |
else{ | |
pos=pos+0; | |
} | |
} | |
cout<<"esta en la pos "<<pos; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment