Created
October 1, 2011 10:51
-
-
Save taruta811/1255872 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstdlib> | |
#include <cmath> | |
#include <cstring> | |
#include <climits> | |
#include <cfloat> | |
#include <map> | |
#include <utility> | |
#include <set> | |
#include <iostream> | |
#include <list> | |
#include <memory> | |
#include <string> | |
#include <vector> | |
#include <algorithm> | |
#include <functional> | |
#include <sstream> | |
#include <complex> | |
#include <stack> | |
#include <queue> | |
using namespace std; | |
typedef long long LL; | |
typedef vector<int> VI; | |
typedef vector<string> VS; | |
typedef pair<int,int> PII; | |
typedef vector<pair<int,int> > VPII; | |
static const double EPS = 1e-9; | |
static const double PI = atan(1.0)*4.0; | |
long long bitcount(long long n){ | |
long long count = 0; | |
while(n != 0){ | |
n&=(n-1); | |
count++; | |
} | |
return count; | |
} | |
int main(int argc, char const* argv[]) { | |
int t; | |
cin >> t; | |
for (int i = 1; i <= t; i++) { | |
long long n; | |
long long max_count = 1; | |
cin >> n; | |
long long ll = 2; | |
int c = 1; | |
while (1) { | |
long long bit; | |
if(ll > n) break; | |
bit = c+bitcount(n-ll+1); | |
if( bit> max_count){ | |
max_count = bit; | |
} | |
c++; | |
ll *= 2; | |
} | |
printf("Case #%d: %lld\n",i,max_count); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment