(高精度)—hdu-6433-Problem H. Pow

本文介绍了一道计数问题的解决方法,通过选择不同数量的3的幂次和来生成不同的数字组合,利用数学和编程手段高效计算所有可能的组合数目。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem H. Pow

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 469    Accepted Submission(s): 187

 

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

 

Source

2018 Multi-University Training Contest 10

 

Recommend

chendu   |   We have carefully selected several similar problems for you:  6437 6436 6435 6434 6433 

 

Statistic | Submit | Discuss | Note

题解:数字 n,有 0 ~ n-1 种,共有 2 的 n 次方的状态。

Java:

import java.math.*;
import java.util.*;
import java.text.*;
import java.io.*;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in=new Scanner(System.in);
        int t=in.nextInt();
        while(t>0){
            BigDecimal a=new BigDecimal(2);
            int n=in.nextInt();
            if(n==0){
                System.out.println("1");
                t--;
                continue;
            }
            for(int i=0;i<n-1;i++){
                a=a.multiply(new BigDecimal(2));
            }
            System.out.println(a);
            t--;
        }
    }
}

c++:

#include<stdio.h>
#include<queue>
#include<string.h>
#include<algorithm>
#include<set>
#include<map>
#include<math.h>
#include<vector>
#include<bitset>
#include<iostream>
#include <bits/stdc++.h>
#define ullmax 1844674407370955161
#define llmax 9223372036854775807
#define intmax 2147483647
#define re register
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        double n;
        cin>>n;
        cout <<fixed<<std::setprecision(0)<<pow(2,n)<<endl;
    }
    return 0;
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值