Live2d Test Env

HDU - 6433: H. Pow (简答题,输出大数)

There are n numbers 3^0, 3^1, . . . , 3^n-1. Each time you can choose a subset of them (may be empty), and then add them up.
Count how many numbers can be represented in this way.

InputThe first line of the input contains an integer T , denoting the number of test cases. In each test case, there is a single integers n in one line, as described above.
1 ≤ T ≤ 20, 0 ≤ n ≤ 1000OutputFor each test case, output one line contains a single integer, denoting the answer.Sample Input

4
9
7
8
233

Sample Output

512
128
256
13803492693581127574869511724554050904902217944340773110325048447598592

题意:给定3^0,3^1...3^N;问子集的和有多少种,因为前缀和小于当前数,所以每次加入都有2种方案(选或不选,其结果不同),所以答案是pow(2,N)。

思路:可以用高精度,也可以直接用pow。

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int T,N;
    scanf("%d",&T);
    while(T--){
        cin>>N;
        cout<<fixed<<setprecision(0)<<pow(2,N)<<endl;
    }
    return 0;
}

 

posted @ 2018-10-21 20:02  nimphy  阅读(171)  评论(0编辑  收藏  举报