Thursday, April 17, 2014

Hackerrank Utopian Tree solution

Hackerrank Utopian Tree: https://www.hackerrank.com/challenges/utopian-tree

Hackerrank Utopian Tree solution: http://ideone.com/tUGW37

#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    int t, n, a;
    scanf("%d", &t);
    while(t--) {
        a=1;
        scanf("%d", &n);
        for(int i=1; i<=n; i++) {
            if(i%2) a<<=1;
            else a++;
        }
        printf("%d\n", a);
    }
    return 0;
}

No comments:

Post a Comment