#include <bits/stdc++.h>
using namespace std;
long long sqr(int x) { return 1ll * x * x; }
using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> a(n), block(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = 0;
  priority_queue<pair<ll, int>, vector<pair<ll, int> >,
                 greater<pair<ll, int> > >
      q;
  auto get = [&](int i, int piece) {
    int temp = a[i] % piece;
    long long res = 0;
    res += 1ll * sqr(a[i] / piece) * (piece - temp);
    res += 1ll * sqr(a[i] / piece + 1) * temp;
    return res;
  };
  for (int i = 0; i < n; i++) {
    ans += 1ll * a[i] * a[i];
    ++block[i];
    q.emplace(get(i, 2) - get(i, 1), i);
    --k;
  }
  while (k--) {
    auto u = q.top();
    q.pop();
    ans += u.first;
    auto i = u.second;
    ++block[i];
    q.emplace(get(i, block[i] + 1) - get(i, block[i]), i);
  }
  cout << ans << '\n';
  return 0;
}
