其实是一个数学题目,地址: http://acm.pku.edu.cn/JudgeOnline/problem?id=2309
#include
<
stdio.h
>
int tab[ 32 ];
void init ()
{
tab[0] = 1;
for ( int i=1; i<32; i++ )
{
tab[i] = tab[i-1]*2;
}
}
int cup ( int n )
{
int i;
for ( i=0; i<32; i++ )
{
if ( n % tab[i] )
{
break;
}
}
return i-1;
}
int main ()
{
int t, n;
int top;
int i;
int min, max;
init ();
while ( scanf ( "%d", &t ) != EOF )
{
while ( t -- )
{
scanf ( "%d", &n );
top = cup ( n );
min = max = n;
for ( i=top-1; i>=0; i-- )
{
min -= tab[i];
max += tab[i];
}
printf ( "%d %d\n", min, max );
}
}
return 0;
}
int tab[ 32 ];
void init ()
{
tab[0] = 1;
for ( int i=1; i<32; i++ )
{
tab[i] = tab[i-1]*2;
}
}
int cup ( int n )
{
int i;
for ( i=0; i<32; i++ )
{
if ( n % tab[i] )
{
break;
}
}
return i-1;
}
int main ()
{
int t, n;
int top;
int i;
int min, max;
init ();
while ( scanf ( "%d", &t ) != EOF )
{
while ( t -- )
{
scanf ( "%d", &n );
top = cup ( n );
min = max = n;
for ( i=top-1; i>=0; i-- )
{
min -= tab[i];
max += tab[i];
}
printf ( "%d %d\n", min, max );
}
}
return 0;
}