chocolate

来源:互联网 发布:淘宝水货单反机身 编辑:程序博客网 时间:2024/04/29 11:25

水题,模拟
二进制分解这种意思。。。。
分成2 4 8 16.。。。。。

#include<cstdio>using namespace std;int n,tot;int main(){    freopen("chocolate.in","r",stdin);    freopen("chocolate.out","w",stdout);    scanf("%d",&n);    while(n)    {        int ans=1,t=0;        while(ans*2<=n){        tot+=ans;        ans*=2;        }        n-=ans;    }    printf("%d",tot);}