#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int vis[300005];
int a[100005];
int cnt[300005];
int n;
int solve(int t){
// cout<<t<<endl;
int step=0;
int temp=t;
while(temp<=100000){
// cout<<temp<<endl;
vis[temp]++;
cnt[temp]+=step;
step++;
temp*=2;
}
step=0;
while(t){
if(t%2==1&&(t!=1)){
t/=2;
vis[t]++;
step++;
cnt[t]+=step;
int tmp=t;
int sstep=step;
while(tmp<=100000){
tmp*=2;
vis[tmp]++;
sstep++;
cnt[tmp]+=sstep;
}
}
else{
t/=2;
vis[t]++;
step++;
cnt[t]+=step;
}
}
}
int main(){
int t;
scanf("%d",&n);
memset(vis,0,sizeof(vis));
memset(cnt,0,sizeof(cnt));
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
solve(a[i]);
}
int ans=10000000;
for(int i=0;i<200000;i++){
if(vis[i]==n){
if(ans>cnt[i]){
ans=cnt[i];
}
}
}
printf("%d\n",ans);
return 0;
}
09-21
04-15
05-09
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交