hdu 5142 NPY and FFT(水)

3619 ワード


http://acm.hdu.edu.cn/showproblem.php?pid=5142

#include<cstdio>

#include<cstring>

#include<cmath>

#include<iostream>

#include<algorithm>

using namespace std;

int bin[100];

int main()

{

    int t,n,i,j,k;

    scanf("%d",&t);

    while(t--)

    {

        scanf("%d",&n);

        memset(bin,0,sizeof(bin));

        int coun=0;

        while(n)

        {

            bin[coun++]=n%2;

            n/=2;

        }

        while(bin[coun]==0) coun--;

        int ans=0;

        int wei=0;

        for(i=coun;i>=0;i--)

        {

            int temp=bin[i]*(int)pow(2,wei++);

            ans+=temp;

            //printf("%d...
",temp);
} printf("%d
",ans); } return 0; }
View Code