#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <signal.h>
#include <bitset>
using namespace std;
typedef unsigned long long uint64 ;
uint64 bitcount64( uint64 dw64) {
dw64 = ( ( dw64 & 0xAAAAAAAAAAAAAAAA ) >> 1 ) + ( dw64 & 0x5555555555555555 ) ;
dw64 = ( ( dw64 & 0xCCCCCCCCCCCCCCCC ) >> 2 ) + ( dw64 & 0x3333333333333333 ) ;
dw64 = ( ( dw64 & 0xF0F0F0F0F0F0F0F0 ) >> 4 ) + ( dw64 & 0x0F0F0F0F0F0F0F0F ) ;
dw64 = ( ( dw64 & 0xFF00FF00FF00FF00 ) >> 8 ) + ( dw64 & 0x00FF00FF00FF00FF ) ;
dw64 = ( ( dw64 & 0xFFFF0000FFFF0000 ) >> 16 ) + ( dw64 & 0x0000FFFF0000FFFF ) ;
dw64 = ( ( dw64 & 0xFFFFFFFF00000000 ) >> 32 ) + ( dw64 & 0x00000000FFFFFFFF ) ;
return dw64;
}
int highbit( uint64 ui64) {
int n = 0 ;
while ( ui64) {
ui64 = ui64 >> 1 ;
n++ ;
}
return n;
}
uint64 calc( uint64 a, uint64 b) {
return bitcount64( a) + bitcount64( b) ;
}
void Solve( std:: istream & stream, int num) {
std:: string line;
getline( stream, line) ;
uint64 N;
#ifdef _LINUX
sscanf ( line.c_str ( ) , "%llu" , & N) ;
#else
sscanf ( line.c_str ( ) , "%I64u" , & N) ;
#endif
// 答えの最大値は一番上のビットまで立っている状態…… なんじゃないかな?
int hb = highbit( N) ;
int max_ans = hb;
uint64 h = N;
uint64 l = 0 ;
uint64 half = N / 2 + 1 ;
uint64 current_max_ans = 0 ;
for ( int i = 0 ; i < half; i++ ) {
uint64 ans = calc( h, l) ;
if ( ans > current_max_ans) {
current_max_ans = ans;
}
h-- ;
l++ ;
}
#ifdef _LINUX
printf ( "Case #%d: %llu\n " , num, current_max_ans) ;
#else
printf ( "Case #%d: %I64u\n " , num, current_max_ans) ;
#endif
}
void sig_handler( int sig) {
}
int main( int argc, char * argv[ ] ) {
std:: string line;
int total_length;
std:: fstream stream( argv[ 1 ] , std:: ios :: in ) ;
if ( stream.fail ( ) )
{
printf ( "fail.\n " ) ;
}
// signal(SIGUSR1, sig_handler);
{
std:: string line;
getline( stream, line) ;
sscanf ( line.c_str ( ) , "%d" , & total_length) ;
//printf("total_length: %d\n", total_length);
}
for ( int n = 0 ; n < total_length; n++ ) {
Solve( stream, n+ 1 ) ;
}
return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGZzdHJlYW0+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPHZlY3Rvcj4gCiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxmdW5jdGlvbmFsPgojaW5jbHVkZSA8c2lnbmFsLmg+CiNpbmNsdWRlIDxiaXRzZXQ+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiB1bnNpZ25lZCBsb25nIGxvbmcgdWludDY0OwoKdWludDY0IGJpdGNvdW50NjQodWludDY0IGR3NjQpewoJZHc2NCA9ICgoZHc2NCAmIDB4QUFBQUFBQUFBQUFBQUFBQSkgPj4gIDEpICsgKGR3NjQgJiAweDU1NTU1NTU1NTU1NTU1NTUpOwoJZHc2NCA9ICgoZHc2NCAmIDB4Q0NDQ0NDQ0NDQ0NDQ0NDQykgPj4gIDIpICsgKGR3NjQgJiAweDMzMzMzMzMzMzMzMzMzMzMpOwoJZHc2NCA9ICgoZHc2NCAmIDB4RjBGMEYwRjBGMEYwRjBGMCkgPj4gIDQpICsgKGR3NjQgJiAweDBGMEYwRjBGMEYwRjBGMEYpOwoJZHc2NCA9ICgoZHc2NCAmIDB4RkYwMEZGMDBGRjAwRkYwMCkgPj4gIDgpICsgKGR3NjQgJiAweDAwRkYwMEZGM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IGhhbGY7IGkrKyl7CgkJdWludDY0IGFucyA9IGNhbGMoaCwgbCk7CgkJaWYoYW5zID4gY3VycmVudF9tYXhfYW5zKXsKCQkJY3VycmVudF9tYXhfYW5zID0gYW5zOwoJCX0KCQloLS07CgkJbCsrOwoJfQoKI2lmZGVmIF9MSU5VWAoJcHJpbnRmKCJDYXNlICMlZDogJWxsdVxuIiwgbnVtLCBjdXJyZW50X21heF9hbnMpOwojZWxzZQoJcHJpbnRmKCJDYXNlICMlZDogJUk2NHVcbiIsIG51bSwgY3VycmVudF9tYXhfYW5zKTsKI2VuZGlmCn0KCnZvaWQgc2lnX2hhbmRsZXIoaW50IHNpZyl7Cn0KCmludCBtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pewoJc3RkOjpzdHJpbmcgbGluZTsKCWludCB0b3RhbF9sZW5ndGg7CglzdGQ6OmZzdHJlYW0gc3RyZWFtKGFyZ3ZbMV0sIHN0ZDo6aW9zOjppbik7CglpZihzdHJlYW0uZmFpbCgpKQoJewoJCXByaW50ZigiZmFpbC5cbiIpOwoJfQoJLy8gc2lnbmFsKFNJR1VTUjEsIHNpZ19oYW5kbGVyKTsKCXsKCQlzdGQ6OnN0cmluZyBsaW5lOwoJCWdldGxpbmUoc3RyZWFtLCBsaW5lKTsKCQlzc2NhbmYobGluZS5jX3N0cigpLCAiJWQiLCAmdG90YWxfbGVuZ3RoKTsKCQkvL3ByaW50ZigidG90YWxfbGVuZ3RoOiAlZFxuIiwgdG90YWxfbGVuZ3RoKTsKCX0KCWZvcihpbnQgbiA9IDA7IG4gPCB0b3RhbF9sZW5ndGg7IG4rKyl7CgkgICAgU29sdmUoc3RyZWFtLCBuKzEpOwoJfQoKCXJldHVybiAwOwp9Cg==
compilation info
prog.cpp:17: error: integer constant is too large for ‘long’ type
prog.cpp:17: error: integer constant is too large for ‘long’ type
prog.cpp:18: error: integer constant is too large for ‘long’ type
prog.cpp:18: error: integer constant is too large for ‘long’ type
prog.cpp:19: error: integer constant is too large for ‘long’ type
prog.cpp:19: error: integer constant is too large for ‘long’ type
prog.cpp:20: error: integer constant is too large for ‘long’ type
prog.cpp:20: error: integer constant is too large for ‘long’ type
prog.cpp:21: error: integer constant is too large for ‘long’ type
prog.cpp:21: error: integer constant is too large for ‘long’ type
prog.cpp:22: error: integer constant is too large for ‘long’ type
prog.cpp: In function ‘void Solve(std::istream&, int)’:
prog.cpp:47: warning: format ‘%I64u’ expects type ‘unsigned int*’, but argument 3 has type ‘uint64*’
prog.cpp:59: warning: comparison between signed and unsigned integer expressions
prog.cpp:71: warning: format ‘%I64u’ expects type ‘unsigned int’, but argument 3 has type ‘uint64’
prog.cpp:52: warning: unused variable ‘max_ans’
stdout