General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
30086367 Practice:
mkisic
850B - 42 GNU C++ Accepted 1435 ms 23696 KB 2017-09-05 02:29:11 2017-09-05 02:29:11
→ Source
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 500005;
int MAGIC;

int n, bio[MAXN * 2];
int divi[MAXN * 2];
int tot[MAXN * 2];

ll x, y, p[MAXN];

vector <int> v, nums;

ll get(int mid) {
  ll d = v[mid];

  ll ret = 0;
  REP(i, (int)nums.size()) {
    if (nums[i] % d == 0) continue;
    ret += (ll)tot[nums[i]] * min(x, y * ((nums[i] / d + 1) * d - nums[i]));
  }

  return ret;
}

int occ[MAXN * 2];

int main() {
  scanf("%d",&n);
  scanf("%lld %lld",&x,&y);
  REP(i, n) scanf("%lld",&p[i]);
  REP(i, n) tot[p[i]]++;
  REP(i, MAXN * 2) if (tot[i]) nums.push_back(i);

  FOR(i, 2, MAXN * 2) {
    if (bio[i]) continue;
    v.push_back(i);
    for (int j = 1; j * i < 2 * MAXN; j++)
      bio[i * j] = 1, divi[i * j] = i;
  }

  ll sol = (1LL << 60);

  MAGIC = min(30000000 / (int)nums.size(), (int)v.size());
  REP(i, MAGIC) sol = min(sol, get(i));

  REP(i, n) {
    ll t = p[i];
    while (t != 1) {
      occ[divi[t]]++;
      int d = divi[t];
      while (t % d == 0) t /= d;
    }
  }
      
  vector <pii> freq;
  
  REP(i, (int)v.size()) freq.push_back(mp(occ[v[i]], i));
  sort(all(freq));
  reverse(all(freq));

  int cnt = MAGIC;
  int i = 0;
  while (cnt && i < (int)v.size()) {
    if (freq[i].sec < MAGIC) {i++; continue;}
    sol = min(sol, get(freq[i].sec));
    cnt--;
    i++;
  }
  printf("%lld\n",sol);
  return 0;
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details