Problem H. PowTime 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. 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. 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 |
题解:数字 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;
}