#include<bits/stdc++.h>
#define ll long long int
using namespace std;
string binary(int n)
{
string s = "";
while(n != 0)
{
int f = n%2;
if(f == 1)
s = s + "1";
else if(f == 0)
s = s + "0";
n = n/2;
}
return s;
}
int main()
{
ll t, n, i, j = 1;
cin >> t;
while(t--)
{
cin >> n;
string s = binary(n);
s = s + "0";
reverse(s.begin(), s.end());
next_permutation(s.begin(), s.end());
reverse(s.begin(), s.end());
ll r = 0, c = 1;
for(i=0;i<s.size();i++)
{
if(s[i] == '1')
r += c;
c = c*2;
}
cout << "Case " << j++ << ": " << r << "\n";
}
return 0;
}
#define ll long long int
using namespace std;
string binary(int n)
{
string s = "";
while(n != 0)
{
int f = n%2;
if(f == 1)
s = s + "1";
else if(f == 0)
s = s + "0";
n = n/2;
}
return s;
}
int main()
{
ll t, n, i, j = 1;
cin >> t;
while(t--)
{
cin >> n;
string s = binary(n);
s = s + "0";
reverse(s.begin(), s.end());
next_permutation(s.begin(), s.end());
reverse(s.begin(), s.end());
ll r = 0, c = 1;
for(i=0;i<s.size();i++)
{
if(s[i] == '1')
r += c;
c = c*2;
}
cout << "Case " << j++ << ": " << r << "\n";
}
return 0;
}
Comments
Post a Comment