Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #include<string>
- #include<vector>
- using namespace std;
- typedef long long int ll;
- typedef long double ld;
- typedef unsigned long long int ull;
- typedef long long li;
- #define ms(x,a) memset(x,a,sizeof(x))
- #define forn(i, n) for (int i = 0; i < int(n); i++)
- #define pi acos(0.0)*2 // 3.1415926535897932
- #define mx 100000007
- #define mod 1000000007
- #define base 10000007
- #define pb push_back
- #define mx1 10001000
- ull ara[mx];
- vector<ull>prime;
- vector<ll>prm;
- void inOut();
- void seive();
- int main()
- {
- //inOut();
- seive();
- ll i,j,k,l,q,n,m;
- string s;
- cin>>n;
- ll a[n+2];
- for(i=0; i<n; i++)
- {
- cin>>a[i];
- for(j=0; j<prime.size(); j++)
- {
- if(a[i] == prime[j])
- {
- prm.pb(a[i]); break;
- }
- }
- }
- sort(a, a+n);
- sort(prm.begin(), prm.end());
- ll sum = 0, lprm;
- ll sz = prm.size();
- for(i=sz-1; i>=0; i--)
- if(prm[i]<a[n-1])
- {
- lprm = prm[i]; break;
- }
- for(i=n-1; i>=0; i--)
- {
- if(a[i] == lprm)
- continue;
- else
- sum += abs(a[i] - lprm);
- }
- cout<<sum<<endl;
- return 0;
- }
- void inOut()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- #endif
- }
- void seive()
- {
- ull i, j, n = mx1, m = n;
- for(i=3; i<=m; i+=2)
- {
- if(ara[i]==0)
- {
- for(j=i*i; j<=n; j+=i*2)
- ara[j] = 1;
- }
- }
- ara[1] = 1;
- for(i=4; i<=n; i+=2)
- ara[i] = 1;
- prime.push_back(1);
- prime.push_back(2);
- for(i=3; i<=n; i+=2)
- {
- if(ara[i]==0)
- prime.push_back(i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement