我是靠谱客的博主 缥缈哑铃,这篇文章主要介绍J - Weird Sanchola Gym - 102302J,现在分享给大家,希望可以做个参考。

Sanchola is getting an array of integers as gift. He's weird, so he doesn't like having distinct integers in the same array and he only likes prime numbers. That's why he believes that he might need to fix the array after receiving it by turning all elements into the same prime number.

Sanchola is also very lazy and wants to do that using the minimum number of operations. In one operation Sanchola can either increase or decrease a single element of the array by one.

Given the array that he received as a gift, help Sanchola figuring out the minimum number of operations required to fix the array.

Input

The first line contains a single integer N

(1≤N≤105)

, indicating the length of the array.

The second line contains N

integers a1, a2, ..., an (1≤N≤109), indicating the elements of the array a

.

Output

In a single line output the minimum number of operations to satisfy Sanchola.

Examples

Input

复制代码
1
2
3 2 3 10

Output

复制代码
1
8

Input

复制代码
1
2
2 1 1000000000

Output

复制代码
1
999999999

Input

复制代码
1
2
4 3 5 7 11

Output

复制代码
1
10
复制代码
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
58
59
60
61
62
63
64
#include <bits/stdc++.h> using namespace std; int prime(int x) { if(x==1||x==0) return 0; else if(x==2) return 1; else { int i; for(i=2; i<=sqrt(x); i++) if(x%i==0) break; if(i>sqrt(x)) return 1; else return 0; } } int main() { int n; long long d,i,j; cin>>n; int a[100010]; for(i=0; i<n; i++) cin>>a[i]; sort(a,a+n); if(n%2==0) { d=(a[n/2]+a[n/2-1])/2; } else d=a[n/2]; long long int sum=0; i=0; j=0; while(1) { if(prime(d+i)==1) break; i++; } while(1) { if(prime(d-j)==1||d==j) break; j++; } long long int num=0; for( int k=0; k<n; k++) sum+=abs(a[k]-d-i); if(j!=d) for( int k=0; k<n; k++) num+=abs(a[k]-d+j); if(j!=d) { sum=min(sum,num); } cout<<sum; return 0; }

最后

以上就是缥缈哑铃最近收集整理的关于J - Weird Sanchola Gym - 102302J的全部内容,更多相关J内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(73)

评论列表共有 0 条评论

立即
投稿
返回
顶部