ACM_ Grab Candy

grab candy

Time Limit: 2000/1000ms (Java/Others)

Problem Description:

Today, the life committee members of the Ji Shi class are in a good mood. They bought a lot of candies in Yongcheng Supermarket. They are very happy~o(∩_∩)o
As soon as she paid the money, she met the foodie, Ajie, who was exploited half of the candy\("▔□▔)/ Fortunately, the conscience of this product was not lost, and she gave it back to the life committee member... Cheeky gone (︶︿︶)
As soon as she stepped out of the supermarket door, she met Sister Yin, who was a cheater, and was exploited in half again! Fortunately, Sister Yin is charitable enough to give her an o_O
After that, she met Brother Feng, Brother Ming, Uncle Tan, Acridine Shrimp, Auntie, Xiaobai, Daughter-in-law... It's so bad, there are only so many people in the JS class, she met n people along the way, and every time she Half of the candy in his hand was taken away, and he got another one.
When she returned to the dormitory, there were only 4 candies left in her hand! Tears ran o(>﹏<)o, but she didn’t eat a single one! Speaking of which, she didn't know how much candy she bought at the beginning, can you help her figure it out?

Input:

The first line of the input data is an integer t, indicating that there are t test instances, each instance has a row, and each row has an integer n (0<n<=30), which represents the number of people encountered.

Output:

For each test instance, please output the number of initial candies, one line per instance.

Sample Input:

6
4
3
2
1
5
29

Sample Output:

34
18
10
6
66
1073741826 
Problem-solving ideas: water problems! ! ! But pay attention that the output value may explode int, when n==30 (1073741826-1)*2=2147483650>2147483647, so use long long for sum, and the water will pass!
AC code:
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int t,n;long long sum;
 6     cin>>t;
 7     while(t--){
 8         cin>>n;
 9         sum=4;
10         while(n--)sum=(sum-1)*2;
11         cout<<sum<<endl;
12     }
13     return 0;
14}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325633963&siteId=291194637