ACM UVA-10892

dp

#define MAX 500001
int N[MAX];
int solution(int n){

    if(N[n])
        return N[n];

    if(n % 2 == 0){
        N[n] = solution(n/2)*2;
    }
    else{
        N[n] = (solution((n+1)/2)-1)*2;
    }

    return N[n];

}
int main(int argc, char const* argv[])
{
    int n;
    N[1] = 1;
    N[2] = 2;
    while(~(scanf("%d",&n)) && n != 0){
        printf("%d\n",solution(n));
    }

    return 0;
}