1
+ #include < iostream>
2
+ #include < cmath>
3
+ #include < vector>
4
+
5
+ #include < algorithm>
6
+ #include < iterator>
7
+
8
+ long long int z (int i,int j, std::vector<long > x,std::vector<long > y){
9
+
10
+ if (j==1 ){return (x[i]^y[i]^1 );}
11
+ else {
12
+ int l=ceil (j/2 );
13
+ return z (i+l,j-l,x,y)&z (i,l,x,y);
14
+ }
15
+
16
+ }
17
+
18
+ long long int t (int i,int j,std::vector<long > x,std::vector<long > y){
19
+ if (j==1 ){
20
+
21
+ return ((x[i]&y[i])^x[i]);
22
+ }
23
+ else {
24
+ int l1=ceil (j/2 );
25
+ return (t (i+l1,j-l1,x,y)^(z (i+l1,j-l1,x,y)&t (i,l1,x,y)));
26
+ }
27
+ }
28
+
29
+
30
+
31
+
32
+ void decToBinary (int n, long binaryNum[])
33
+ {
34
+
35
+ int i = 0 ;
36
+ while (n > 0 ) {
37
+
38
+
39
+ binaryNum[i] = n % 2 ;
40
+ n = n / 2 ;
41
+ i++;
42
+ }
43
+
44
+
45
+ }
46
+
47
+
48
+ std::vector<long > minimum (std::vector<long > x,std::vector<long > y,long int t){
49
+
50
+ std::vector<long > flag (x.size (),0 );
51
+
52
+ for (int i=0 ;i<y.size ();i++){
53
+
54
+ flag[i]=((x[i]&1 )^t)^(t&y[i]);
55
+
56
+ }
57
+ return flag;
58
+ }
59
+
60
+ std::vector<long > listmin (std::vector<std::vector<long > > list){
61
+
62
+ std::vector<long > min;
63
+ min=list[0 ];
64
+ for (int i=1 ;i<list.size ();i++){
65
+ long int tau=0 ;
66
+ tau=t (0 ,min.size ()-1 ,min,list[i]);
67
+ min=minimum (min,list[i], tau);
68
+ }
69
+ return min;
70
+ }
71
+
72
+
73
+ int main (){
74
+
75
+ int m,n,q;
76
+ std::cout << " give me three numbers" << std::endl;
77
+ std::cout<< " first:" ;
78
+ std::cin >> n;
79
+ std::cout<< " second:" ;
80
+ std::cin >> m;
81
+ std::cout<< " third:" ;
82
+ std::cin >> q;
83
+
84
+
85
+ int binarysizen=floor (log2 (n)) + 1 ;
86
+ long x[binarysizen];
87
+ decToBinary (n,x);
88
+
89
+ int binarysizem=floor (log2 (m)) + 1 ;
90
+ long y[binarysizem];
91
+ decToBinary (m,y);
92
+
93
+
94
+ int binarysizeq=floor (log2 (q)) + 1 ;
95
+ long z[binarysizeq];
96
+ decToBinary (q,z);
97
+
98
+
99
+
100
+ size_t x_size = sizeof (x)/sizeof (x[0 ]);
101
+ std::reverse (x, x + x_size);
102
+ size_t y_size = sizeof (y)/sizeof (y[0 ]);
103
+ std::reverse (y, y + y_size);
104
+ size_t z_size = sizeof (z)/sizeof (z[0 ]);
105
+ std::reverse (z, z + z_size);
106
+
107
+
108
+
109
+ std::vector<long > v (x, x + sizeof x / sizeof x[0 ]);
110
+ std::vector<long > c (y, y + sizeof y / sizeof y[0 ]);
111
+ std::vector<long > k (z, z + sizeof z / sizeof z[0 ]);
112
+
113
+
114
+
115
+
116
+
117
+ std::vector<std::vector<long > > list;
118
+
119
+ list.push_back (v);
120
+ list.push_back (c);
121
+ list.push_back (k);
122
+
123
+
124
+
125
+
126
+
127
+ std::cout << std::endl;
128
+
129
+
130
+
131
+ // std::cout << "the minimum of the first two is:"<< number;
132
+
133
+
134
+ if ((binarysizen>binarysizem) && (binarysizeq>binarysizem)){
135
+ std::cout<< " the minimum is:" << m;
136
+ return 0 ;
137
+ }
138
+ else if ((binarysizen<binarysizem) && (binarysizen<binarysizeq)){
139
+ std::cout << " the minimum is:" << n;
140
+ return 0 ;
141
+ }
142
+ else if ((binarysizen>binarysizeq) && (binarysizeq<binarysizem)){
143
+ std::cout<< " the minimum is:" << q;
144
+ return 0 ;
145
+ }
146
+ else {
147
+
148
+ std::vector<long > f=listmin (list);
149
+
150
+ std::cout << std::endl;
151
+
152
+ int number=0 ,g=0 ;
153
+ for (int i=0 ;i< binarysizen;i++){
154
+ g=pow (2 ,i)*f[(binarysizen-1 ) - i];
155
+ number=number+g;
156
+ }
157
+ std::cout << " the minimum:" << number << std::endl;
158
+ return 0 ;
159
+ }
160
+ }
0 commit comments