98 lines
1.8 KiB
C++
98 lines
1.8 KiB
C++
/*
|
|
VIM: let g:lcppflags="-std=c++11 -O2 -pthread"
|
|
VIM: let g:wcppflags="/O2 /EHsc /DWIN32"
|
|
*/
|
|
|
|
#include <assert.h>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <fstream>
|
|
#include <iomanip>
|
|
#include <exception>
|
|
#include <stdexcept>
|
|
#include <map>
|
|
#include <set>
|
|
#include <list>
|
|
#include <vector>
|
|
#include <string>
|
|
#include <memory>
|
|
#include <functional>
|
|
#include <algorithm>
|
|
#include <utility>
|
|
#include <limits>
|
|
#include <math.h>
|
|
|
|
typedef long long ll;
|
|
typedef std::vector<ll> vec;
|
|
|
|
template <typename T>
|
|
std::string to_string( T t ){
|
|
std::stringstream ss;
|
|
ss << t;
|
|
return ss.str();
|
|
}
|
|
|
|
/*
|
|
*/
|
|
|
|
auto solve_puzzle(std::istream& is)
|
|
{
|
|
long long n, k;
|
|
is >> n >> k;
|
|
|
|
long long sec=1;
|
|
for ( long long kk = k; kk; kk>>=1, sec<<=1 ); //exp2( (int)ceil(log2( k+1 )) );
|
|
long long empty = n - sec +1;
|
|
long long min = empty / sec;
|
|
long long rem = empty % sec;
|
|
long long max = min;
|
|
if ( (rem - (sec/2)) >= (k-sec/2+1) ) {
|
|
max = min += 1;
|
|
} else if ( rem >= (k-sec/2+1) ) {
|
|
max = min + 1;
|
|
}
|
|
|
|
return to_string(max) + ' ' + to_string(min);
|
|
}
|
|
|
|
void read_input_and_solve( std::istream& is, std::ostream& os )
|
|
{
|
|
srand((unsigned)time(NULL));
|
|
int puzzle_count;
|
|
|
|
is >> puzzle_count;
|
|
is.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
|
for (int i = 1; i <= puzzle_count; i++)
|
|
{
|
|
os << "Case #" << i << ": ";
|
|
auto r = solve_puzzle(is);
|
|
os << r << std::endl;
|
|
}
|
|
}
|
|
|
|
int main(int argc, char * argv[])
|
|
{
|
|
try{
|
|
if ( *++argv ) {
|
|
std::ifstream ifs(*argv);
|
|
read_input_and_solve( ifs, std::cout );
|
|
} else {
|
|
read_input_and_solve( std::cin, std::cout );
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
catch (const std::exception& e)
|
|
{
|
|
std::cerr << std::endl
|
|
<< "std::exception(\"" << e.what() << "\")." << std::endl;
|
|
return 2;
|
|
}
|
|
catch (...)
|
|
{
|
|
std::cerr << std::endl
|
|
<< "unknown exception." << std::endl;
|
|
return 1;
|
|
}
|
|
}
|