#include <bits/stdc++.h>
using namespace std;
long long f(long long l, long long p) {
  long long p1, p2;
  p2 = l % p;
  p1 = p - p2;
  return p1 * (l / p) * (l / p) + p2 * (l / p + 1) * (l / p + 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  vector<long long> cnt(n, 1), a(n);
  for (auto& x : a) {
    cin >> x;
  }
  auto cmp = [&](const int& i, const int& j) {
    return f(a[i], cnt[i]) - f(a[i], cnt[i] + 1) <
           f(a[j], cnt[j]) - f(a[j], cnt[j] + 1);
  };
  priority_queue<int, vector<int>, decltype(cmp)> pq(cmp);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    pq.push(i);
    ans += f(a[i], cnt[i]);
  }
  int tot = k - n;
  while (tot--) {
    int id = pq.top();
    pq.pop();
    long long before = f(a[id], cnt[id]), after = f(a[id], ++cnt[id]);
    ans += (after - before);
    pq.push(id);
  }
  cout << ans << '\n';
  return 0;
}
