-
Notifications
You must be signed in to change notification settings - Fork 64
/
Bitwise.c
54 lines (49 loc) · 953 Bytes
/
Bitwise.c
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
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
//Complete the following function.
void calculate_the_maximum(int n, int k)
{
int i,j,add=0,orr=0,xorr=0;
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
if((i&j)<k&&add<(i&j))
{
add=i&j;
}
}
}
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
if((i|j)<k&&orr<(i|j))
{
orr=i|j;
}
}
}
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
if((i^j)<k&&xorr<(i^j))
{
xorr=i^j;
}
}
}
printf("%d\n",add);
printf("%d\n",orr);
printf("%d\n",xorr);
}
int main()
{
int n, k;
scanf("%d %d", &n, &k);
calculate_the_maximum(n, k);
return 0;
}