-
Notifications
You must be signed in to change notification settings - Fork 7
/
LightOj 1042.cpp
72 lines (66 loc) · 1.09 KB
/
LightOj 1042.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
using namespace std;
char s[10000000];
void rev()
{
int i,len=strlen(s)-1;
char a;
for(i=0;i<=len/2;i++){
a=s[i];
s[i]=s[len-i];
s[len-i]=a;
}
}
void bin(unsigned long long n)
{
unsigned long long i=0,j;
while(n!=0){
s[i++]=48+n%2;
n=n/2;
}
s[i++]='0';
s[i]='\0';
rev();
}
unsigned long long dec()
{
int i;
unsigned long long n=0,a=1;
for(i=strlen(s)-1;i>=0;i--){
n+=((s[i]-48)*a);
a*=2;
}
return n;
}
int main()
{
int i,j,k,t,tcase=1,l;
unsigned long long n,m;
scanf("%d",&t);
while(t--){
scanf("%llu",&n);
bin(n);
l=strlen(s);
next_permutation(s,s+l);
m=dec();
printf("Case %d: %llu\n",tcase++,m);
}
return 0;
}