Hackerrank Utopian Tree Solution

This is the solution to the program in Hackerrank. This program can be found in the Algorithm Domain. Basically the Utopian Tree goes through 2 cycles of growth every year. The first growth cycle occurs during the spring, when it doubles in height. The second growth cycle occurs during the summer, when its height increases by 1 meter.

 Screenshot

The Code:

#include<stdio.h>
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("%dn", a);
}
return 0;
}

Found bugs, report them !

Catch Me On

Bikash Panda

Blogger / Embedded System Developer at WGLabz
A techie, tinkerer and tech lover, who loves to blog and feels everyone can learn tech provided they have the right attitude towards learning and passion. By profession, I am an IOT developer working in Smart Home/ Smart Grid domain.
Bikash Panda
Catch Me On

Latest posts by Bikash Panda (see all)

Related posts