#include <bits/stdc++.h>
using namespace std;
const long long BAD = -999999999999999999;
class PhawintervalTree {
 private:
  class MaxMinInfo {
   public:
    long long value;
    int index;
    MaxMinInfo(long long val = 0, int idx = -1) : value(val), index(idx) {}
    bool operator<(const MaxMinInfo &that) const {
      if (value != that.value) return value < that.value;
      return index < that.index;
    }
    bool operator>(const MaxMinInfo &that) const {
      if (value != that.value) return value > that.value;
      return index > that.index;
    }
    void addValue(long long val) { value += val; }
  };
  class Node {
   public:
    long long value;
    bool lazyMark;
    long long lazySet;
    long long lazyAdd;
    int lb, ub;
    int lc, rc;
    long long mySum;
    MaxMinInfo myMin, myMax;
    Node(int lower = 0, int upper = 0)
        : value(0),
          lazyMark(false),
          lazySet(0),
          lazyAdd(0),
          lb(lower),
          ub(upper),
          lc(-1),
          rc(-1),
          mySum(0),
          myMin(MaxMinInfo()),
          myMax(MaxMinInfo()) {}
    void setChildren(int leftChild, int rightChild) {
      lc = leftChild;
      rc = rightChild;
    }
  };
  int ROOT;
  vector<Node> node;
  int getNode(Node newNode = Node()) {
    int z = node.size();
    node.push_back(newNode);
    return z;
  }
  int myHalf(int l, int r) { return l + (r - l) / 2; }

 private:
  void reCalculate(int idx) {
    int lc = node[idx].lc;
    int rc = node[idx].rc;
    node[idx].mySum = node[lc].mySum + node[rc].mySum;
    node[idx].myMin = min(node[lc].myMin, node[rc].myMin);
    node[idx].myMax = max(node[lc].myMax, node[rc].myMax);
  }
  int buildNode(int l, int r) {
    int idx = getNode(Node(l, r));
    if (l == r) {
      node[idx].myMin = MaxMinInfo(0, l);
      node[idx].myMax = MaxMinInfo(0, r);
      return idx;
    }
    int h = myHalf(l, r);
    int lc = buildNode(l, h);
    int rc = buildNode(h + 1, r);
    node[idx].setChildren(lc, rc);
    reCalculate(idx);
    return idx;
  }
  void passLazySet(int idx, long long toSet) {
    if (idx == -1) return;
    node[idx].lazyMark = true;
    node[idx].lazySet = toSet;
    node[idx].lazyAdd = 0;
  }
  void passLazyAdd(int idx, long long toAdd) {
    if (idx == -1) return;
    node[idx].lazyAdd += toAdd;
  }
  void resolveLazy(int idx) {
    if (idx == -1) return;
    long long itemCount = node[idx].ub - node[idx].lb + 1;
    if (node[idx].lazyMark) {
      node[idx].lazyMark = false;
      node[idx].mySum = itemCount * node[idx].lazySet;
      node[idx].myMax = MaxMinInfo(node[idx].lazySet, node[idx].ub);
      node[idx].myMin = MaxMinInfo(node[idx].lazySet, node[idx].lb);
      passLazySet(node[idx].lc, node[idx].lazySet);
      passLazySet(node[idx].rc, node[idx].lazySet);
    }
    if (node[idx].lazyAdd != 0) {
      passLazyAdd(node[idx].lc, node[idx].lazyAdd);
      passLazyAdd(node[idx].rc, node[idx].lazyAdd);
      node[idx].mySum += itemCount * node[idx].lazyAdd;
      node[idx].myMax.addValue(node[idx].lazyAdd);
      node[idx].myMin.addValue(node[idx].lazyAdd);
      node[idx].lazyAdd = 0;
    }
    return;
  }
  void addUpdate(int idx, int l, int r, long long val) {
    resolveLazy(idx);
    int lb = node[idx].lb;
    int ub = node[idx].ub;
    if (ub < l || r < lb) return;
    if (l <= lb && ub <= r) {
      passLazyAdd(idx, val);
      resolveLazy(idx);
      return;
    }
    addUpdate(node[idx].lc, l, r, val);
    addUpdate(node[idx].rc, l, r, val);
    reCalculate(idx);
    return;
  }
  void setUpdate(int idx, int l, int r, long long val) {
    resolveLazy(idx);
    int lb = node[idx].lb;
    int ub = node[idx].ub;
    if (ub < l || r < lb) return;
    if (l <= lb && ub <= r) {
      passLazySet(idx, val);
      resolveLazy(idx);
      return;
    }
    setUpdate(node[idx].lc, l, r, val);
    setUpdate(node[idx].rc, l, r, val);
    reCalculate(idx);
    return;
  }
  long long sumHunt(int idx, int l, int r) {
    resolveLazy(idx);
    int lb = node[idx].lb;
    int ub = node[idx].ub;
    if (ub < l || r < lb) return 0;
    if (l <= lb && ub <= r) return node[idx].mySum;
    int lc = node[idx].lc;
    int rc = node[idx].rc;
    return sumHunt(lc, l, r) + sumHunt(rc, l, r);
  }
  MaxMinInfo minHunt(int idx, int l, int r) {
    resolveLazy(idx);
    int lb = node[idx].lb;
    int ub = node[idx].ub;
    if (ub < l || r < lb) return MaxMinInfo(999999999999999999, -1);
    if (l <= lb && ub <= r) return node[idx].myMin;
    int lc = node[idx].lc;
    int rc = node[idx].rc;
    return min(minHunt(lc, l, r), minHunt(rc, l, r));
  }
  MaxMinInfo maxHunt(int idx, int l, int r) {
    resolveLazy(idx);
    int lb = node[idx].lb;
    int ub = node[idx].ub;
    if (ub < l || r < lb) return MaxMinInfo(-999999999999999999, -1);
    if (l <= lb && ub <= r) return node[idx].myMax;
    int lc = node[idx].lc;
    int rc = node[idx].rc;
    return max(maxHunt(lc, l, r), maxHunt(rc, l, r));
  }

 public:
  PhawintervalTree(int n = 1) { ROOT = buildNode(0, n - 1); }
  void rangeAdd(int l, int r, long long val) { addUpdate(ROOT, l, r, val); }
  void rangeSet(int l, int r, long long val) { setUpdate(ROOT, l, r, val); }
  long long getSum(int l, int r) { return sumHunt(ROOT, l, r); }
  long long getMin(int l, int r) { return minHunt(ROOT, l, r).value; }
  int getMinIndex(int l, int r) { return minHunt(ROOT, l, r).index; }
  long long getMax(int l, int r) { return maxHunt(ROOT, l, r).value; }
  int getMaxIndex(int l, int r) { return maxHunt(ROOT, l, r).index; }
};
long long getCost(long long l, long long w) {
  long long baseline = l / w;
  long long expensiveCount = l - w * baseline;
  long long cheapCount = w - expensiveCount;
  return (baseline + 1) * (baseline + 1) * expensiveCount +
         baseline * baseline * cheapCount;
}
long long getMinimumTimePenalty(int n, int k, vector<long long> a) {
  vector<int> curPartition(n, 1);
  vector<long long> curCost(n);
  for (int i = 0; i < n; i++) curCost[i] = a[i] * a[i];
  PhawintervalTree tree(n);
  for (int i = 0; i < n; i++) {
    long long thisRound = BAD;
    if (curPartition[i] < a[i]) {
      long long nextReturn = getCost(a[i], curPartition[i] + 1);
      thisRound = curCost[i] - nextReturn;
    }
    tree.rangeSet(i, i, thisRound);
  }
  int cutRemain = k - n;
  while (cutRemain--) {
    int idx = tree.getMaxIndex(0, n - 1);
    curPartition[idx]++;
    curCost[idx] = getCost(a[idx], curPartition[idx]);
    long long thisRound = BAD;
    if (curPartition[idx] < a[idx]) {
      long long nextReturn = getCost(a[idx], curPartition[idx] + 1);
      thisRound = curCost[idx] - nextReturn;
    }
    tree.rangeSet(idx, idx, thisRound);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) ans += curCost[i];
  return ans;
}
int main() {
  int tc = 1;
  while (tc--) {
    int n, k;
    scanf("%d%d", &n, &k);
    vector<long long> a(n);
    for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
    long long ans = getMinimumTimePenalty(n, k, a);
    printf("%lld\n", ans);
  }
  return 0;
}
