-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitwise.c
57 lines (44 loc) · 819 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
55
56
57
#include "stdio.h"
#define get getchar_unlocked
inline long int scan2(){
long int n=0,s=1;
char p=get();
if(p=='-') s=-1;
while((p<'0'||p>'9')&&p!=EOF&&p!='-') p=get();
if(p=='-') s=-1,p=get();
while(p>='0'&&p<='9') { n = (n<< 3) + (n<< 1) + (p - '0'); p=get(); }
return n*s;
}
int main(){
int n = 0;
long int i,j,nums[1000000];
long long int sum = 0,temp = 0,flag = 0,c = 0;
long numones = 0;
n = scan2();
for(i=0;i<n;i++){
c = scan2();
nums[i] = c;
if(c==1)
numones++;
if(c!=1 || c!=0)
flag = 1;
}
if(flag == 1){
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
sum += (nums[i] & nums[j]);
}
}
}
else{
if(numones%2 == 0){
sum = (numones/2)*(numones-1);
}else{
sum = ((numones-1)/2)*numones;
}
}
printf("%lld",sum);
sum = 0;
numones = 0;
return 0;
}