#include <bits/stdc++.h>
using namespace std;
struct Node {
  vector<int> neighs;
};
int k;
vector<Node> nodes;
long long ans = 0;
vector<vector<long long>> s, c;
void DFS(int root, int parent) {
  for (int u : nodes[root].neighs) {
    if (u == parent) continue;
    DFS(u, root);
  }
  for (int mod = 0; mod < k; mod++) {
    int next_mod = (mod + 1) % k;
    for (int i : nodes[root].neighs) {
      if (i == parent) continue;
      s[next_mod][root] += s[mod][i];
      if (mod == k - 1) s[next_mod][root] += c[mod][i];
      c[next_mod][root] += c[mod][i];
    }
  }
  c[0][root]++;
  for (int i = 0; i < k; i++) {
    long long junk = (i + 1) / k;
    if ((i + 1) % k != 0) junk++;
    for (int u : nodes[root].neighs) {
      if (u == parent) continue;
      ans += junk * c[i][u] + s[i][u];
    }
    for (int j = 0; j < k; j++) {
      junk = (i + j + 2) / k;
      if ((i + j + 2) % k != 0) junk++;
      long long part_sum_ci = 0;
      long long part_sum_si = 0;
      for (int u : nodes[root].neighs) {
        if (u == parent) continue;
        ans += junk * c[j][u] * part_sum_ci;
        ans += s[j][u] * part_sum_ci + c[j][u] * part_sum_si;
        part_sum_ci += c[i][u];
        part_sum_si += s[i][u];
      }
    }
  }
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n >> k;
  nodes.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    nodes[a].neighs.push_back(b);
    nodes[b].neighs.push_back(a);
  }
  s.resize(k);
  c.resize(k);
  for (int mod = 0; mod < k; mod++) {
    s[mod].resize(n);
    c[mod].resize(n);
  }
  DFS(0, -1);
  cout << ans << '\n';
  return 0;
}
