contest 1.19

A.Little Sub and Pascal's Triangle

求帕斯卡三角形第n行(n=0,1,...)的奇数个数

规律:

#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
typedef long long ll;
using namespace std;

ll f(ll x){
  if(x==0) return 1;
  ll now=1;
  while(now*2<=x) now*=2;
  return 2*f(x-now);
}

int main()
{
    ll t;scanf("%lld",&t);
    while(t--){
        ll k;scanf("%lld",&k);
        k--;
        ll ans=f(k);
        printf("%lld\n",ans);
    }
    return 0;
}
View Code

猜你喜欢

转载自www.cnblogs.com/lllxq/p/10291488.html