hdu6433 pow(大数运算)

                                     Problem H. Pow

                       Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
                                   Submission(s): 621    Accepted Submission(s): 249


 

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

题意:相当于比较大的2进制转换。

yhx大佬思路指导:利用数组存下来每一位数字,直接模拟乘法。

#include <bits/stdc++.h>
#define in(a) scanf("%d",&a)
using namespace std;
const double pi = acos(-1);
int main()
{
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        in(n);
        int ans[2000];
        memset(ans,0,sizeof(ans));
        int wei=(double)n*log(2)/log(10);
        ans[0]=1;
        for(int i=0;i<n;i++)
        {
            for(int j=wei;j>=0;j--)
            {
                ans[j]*=2;
                if(ans[j]>9)
                {
                    ans[j+1]++;
                    ans[j]%=10;
                }
            }
        }
        for(int i=wei;i>=0;i--)
            printf("%d",ans[i]);
        puts("");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sadsummerholiday/article/details/81974941
pow