Problem H. Pow
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
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.
Input
The 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 ≤ 1000
Output
For 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
java大数模板 !!!package文件名要去掉
class一定要写 Main
import java.math.*;
import java.util.*;
public class Main {
public static BigInteger num;
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int T=cin.nextInt();
for(int i=1;i<=T;i++){
int n=cin.nextInt();
num = BigInteger.ONE;
for (int j = 1; j <= n; j++) {
num= num.multiply(BigInteger.valueOf(2));
}
System.out.println(num);
}
}
}
C++ 2的n次方模板
#include<iostream>
#include<cstring>
using namespace std;
int a[100000], b[100000];
int main()
{
int T;
cin >> T;
while ( T -- )
{
memset ( a, 0, sizeof ( a ) );
memset ( b, 0, sizeof ( b ) );
int n, i, j, k;
cin >> n;
memset ( a, 0, sizeof ( a ) );
a[1] = 1;
int size = 1;
int x;
for ( i = 1; i <= n; i++ )
{
x = 0;
for ( j = 1; j <= size; j++ )
{
a[j] = a[j] * 2 + x;
x = a[j] / 10;
a[j] %= 10;
}
if ( x > 0 )
{
size++;
a[size] = x;
}
}
for ( i = size; i >= 1; i-- )
cout << a[i];
printf("\n");
}
return 0;
}