码迷,mamicode.com
首页 > 其他好文 > 详细

contest 1.19

时间:2019-01-19 14:22:56      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:event   .com   nbsp   stp   alt   href   algo   ttl   col   

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

 

contest 1.19

标签:event   .com   nbsp   stp   alt   href   algo   ttl   col   

原文地址:https://www.cnblogs.com/lllxq/p/10291488.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!