ZOJ Monthly, January 2019 - A Little Sub and Pascal's Triangle(找規律)

ZMST發表於2019-01-19

題目連結:

Lucas定理:

2的p次方,p為n-1二進位制中1的個數

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
int main()
{
    ll n;
    int t;
    scanf("%d",&t);
    while (t--)
    {
        scanf("%lld",&n);
        ll cnt=0;
        n--;
        while (n)
        {
            if(n&1)
                cnt++;
            n>>=1;
        }
        ll ans=1ll<<cnt;
        printf("%lld\n",ans);
    }
    return 0;
}

 

相關文章