翻转一下然后求和即可,直接暴力位运算就行。
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
# include<iostream>
# include<iomanip>
# include<algorithm>
# include<cmath>
# include<cstdio>
# include<set>
# include<stack>
# include<queue>
# include<map>
# include<string>
# include<cstring>
# define eps 1e-9
# define fi first
# define se second
# define ll long long
# define int ll
// cout<<fixed<<setprecision(n)
using namespace std;
typedef unsigned long long ull;
typedef pair<int,int > PII;
const int mod=10000003;
const int MAX=1e7+10;
const int Time=86400;
const int X=131;
const int inf=0x3f3f3f3f;
const double PI = 1e-4;
double pai = 3.14159265358979323846;
priority_queue<PII,vector<PII>,greater<PII>>q1;
priority_queue<PII,vector<PII>,less<PII>>q2;
int n,x,a[32];
int ans;
signed main(){
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n ;
while(n--){
int j = 0;
cin >> x;
while(pow(2,j) <= x) j++;
j--;
for(int i = 0 ; i <= 31 ; i ++ ){
if(x >> i & 1){
a[i] = 1;
}
else a[i] = 0;
}
for(int i = 0 ; i <= j ; i ++ )
ans += pow(2,j-i) * a[i];
}
cout<<ans;
return 0;
}