【java大数模板+C++2的n次方模板】hdu 2018 多校第十场 Problem H. Pow hdu 6433

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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值