#include <bits/stdc++.h>
using namespace std;
int n, k;
long long res = 0;
vector<int> e[200000];
long long v[200000][6], sum[200000];
long long r[6];
void dfs(int x, int f) {
  for (auto i : e[x]) {
    if (i == f) continue;
    dfs(i, x);
    for (int j = k - 1; j >= 0; j--) v[i][j + 1] = v[i][j];
    v[i][0] = v[i][k];
    for (int j = 0; j < k; j++) v[x][j] += v[i][j];
    sum[x] += sum[i];
  }
  sum[x]++;
  v[x][0]++;
  for (auto i : e[x]) {
    if (i == f) continue;
    for (int ii = 0; ii < k; ii++)
      for (int j = 0; j < k; j++) {
        r[(ii + j) % k] += 1ll * v[i][ii] * (v[x][j] - v[i][j]);
        if (!j) r[(ii + j) % k] += v[i][ii];
      }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    e[y].push_back(x);
    e[x].push_back(y);
  }
  dfs(0, 0);
  for (int i = 0; i < n; i++) res += 1ll * sum[i] * (n - sum[i]);
  for (int i = 1; i < k; i++) res += 1ll * r[i] * (k - i) / 2;
  cout << res / k;
  return 0;
}
