#include <bits/stdc++.h>
using namespace std;
const int SO = 2e5 + 5;
int n, k;
long long f[SO][6], g[SO][6], b[SO][6], kq;
vector<int> ke[SO];
long long fix(long long so) { return ((so + k) % k); }
long long fixx(long long so) {
  long long b = 0;
  return max(so, b);
}
void DFS(int u, int p) {
  int dem = 0;
  long long tf[6], tg[6];
  for (int c = 0; c < ke[u].size(); c++) {
    int v = ke[u][c];
    if (v != p) {
      DFS(v, u);
      dem++;
      for (int i = 0; i < k; i++) {
        f[u][i] += f[v][fix(i - 1)];
        tf[i] += f[v][fix(i - 1)];
        g[u][i] += g[v][fix(i - 1)];
        b[v][i] = g[v][fix(i - 1)];
      }
      g[u][0] += f[v][k - 1];
      b[v][0] += f[v][k - 1];
    }
  }
  long long kqq = 0;
  if (dem > 1)
    for (int c = 0; c < ke[u].size(); c++) {
      int v = ke[u][c];
      if (v != p) {
        for (int i = 0; i < k; i++)
          for (int j = 0; j < k; j++)
            kqq += f[v][fix(i - 1)] * (g[u][j] - b[v][j]) +
                   b[v][i] * (f[u][j] - f[v][fix(j - 1)]) +
                   f[v][fix(i - 1)] * (f[u][j] - f[v][fix(j - 1)]) *
                       fixx((i + j - 1) / k + 1 - ((i + j) == 0));
      }
    }
  kq += kqq / 2;
  for (int i = 0; i < k; i++) {
    kq += g[u][i];
    if (i > 0) kq += f[u][i];
  }
  f[u][0]++;
  return;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    ke[x].push_back(y);
    ke[y].push_back(x);
  }
  DFS(1, 0);
  printf("%I64d", kq);
  return 0;
}
