您的位置:首页 > 其它

【瞎搞】 UVALive 6527 Counting ones

2014-11-01 14:43 411 查看
题目地址

例:

0000

0001

0010

0011

0100

0101

0110

0111

每一位上的个数都是 每 2^i的数 最后2^(i-1)都为 1   

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cmath>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#define cler(arr, val) memset(arr, val, sizeof(arr))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define IN freopen ("in.txt" , "r" , stdin);
#define OUT freopen ("out.txt" , "w" , stdout);
typedef long long LL;
const int MAXN = 10052;
const int MAXM = 6000010;
const int INF = 0x3f3f3f3f;
const int mod = 1e9;
const double eps= 1e-8;
#define lson l,m, rt<<1
#define rson m+1,r,rt<<1|1
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
LL a,b;
while(cin>>a>>b)
{
a--;
LL sum1=0,sum2=0;
LL n=a;
LL i=0;
while(n)
{
i++;
LL po=(LL)pow(2,i);
LL po2=(LL)pow(2,i-1);
LL moo=a%po;
if(moo>=po/2)
sum1+=a/po*po2+moo-(po2-1);
else sum1+=a/po*po2;
n/=2;
}
n=b;
i=0;
while(n)
{
i++;
LL po=(LL)pow(2,i);
LL po2=(LL)pow(2,i-1);
LL moo=b%po;
if(moo>=po/2)
sum2+=b/po*po2+moo-(po2-1);
else sum2+=b/po*po2;
n/=2;
}
cout<<sum2-sum1<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: