1 /****************************************************
2
3 Author : Coolxxx
4 Copyright 2017 by Coolxxx. All rights reserved.
5 BLOG : http://blog.csdn.net/u010568270
6
7 ****************************************************/
8 #include<bits/stdc++.h>
9 #pragma comment(linker,"/STACK:1024000000,1024000000")
10 #define abs(a) ((a)>0?(a):(-(a)))
11 #define lowbit(a) (a&(-a))
12 #define sqr(a) ((a)*(a))
13 #define mem(a,b) memset(a,b,sizeof(a))
14 const double EPS=0.00001;
15 const int J=10;
16 const int MOD=100000007;
17 const int MAX=0x7f7f7f7f;
18 const double PI=3.14159265358979323;
19 const int N=104;
20 const int M=65544;
21 using namespace std;
22 typedef long long LL;
23 double anss;
24 LL aans;
25 int cas,cass;
26 int n,m,lll,ans;
27 int p[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
28 int a[N],fj[N];
29 int f[N][M];
30 void init()
31 {
32 int i,j,x;
33 for(i=1;i<59;i++)
34 {
35 x=i;
36 fj[i]=0;
37 for(j=0;j<16;j++)
38 {
39 while(x%p[j]==0)
40 {
41 x/=p[j];
42 fj[i]|=(1<<j);
43 }
44 if(x==1)break;
45 }
46 }
47 }
48 int main()
49 {
50 #ifndef ONLINE_JUDGE
51 // freopen("1.txt","r",stdin);
52 // freopen("2.txt","w",stdout);
53 #endif
54 int i,j,k;
55 int x,y,z;
56 // for(scanf("%d",&cass);cass;cass--)
57 // for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
58 init();
59 while(~scanf("%d",&n))
60 {
61 mem(f,0x7f);
62 for(i=1;i<=n;i++)
63 scanf("%d",&a[i]);
64 sort(a+1,a+1+n,greater<int>());
65 f[0][0]=0;
66 for(i=1;i<=min(n,16);i++)
67 {
68 for(j=0;j<(1<<16);j++)
69 {
70 if(f[i-1][j]==MAX)continue;
71 for(k=1;k<=a[i]+a[i]-1;k++)
72 {
73 if(fj[k] & j)continue;
74 f[i][j|fj[k]]=min(f[i][j|fj[k]],f[i-1][j]+abs(a[i]-k));
75 }
76 }
77 }
78 ans=MAX;
79 for(i=0;i<(1<<16);i++)
80 ans=min(ans,f[min(n,16)][i]);
81 if(n>16)
82 {
83 for(i=17;i<=n;i++)
84 ans+=a[i]-1;
85 }
86 printf("%d\n",ans);
87 }
88 return 0;
89 }
90 /*
91 //
92
93 //
94 */