#include <bits/stdc++.h>
using namespace std;
typedef struct {
  int toward, next;
} Edge;
Edge e[300000 * 2];
long long f[300000][5], s[300000][5], sum;
int n, tot, m, chose[300000], fi[300000];
void addedge(int j, int k) {
  ++tot;
  e[tot].toward = k;
  e[tot].next = fi[j];
  fi[j] = tot;
}
void dfs(int x) {
  chose[x] = 1;
  f[x][0] = 0, s[x][0] = 1;
  for (int i = fi[x]; i; i = e[i].next) {
    int too = e[i].toward;
    if (!chose[too]) {
      dfs(too);
      for (int j = 0; j <= m - 1; j++)
        if (s[x][j])
          for (int k = 0; k <= m - 1; k++)
            if (s[too][k]) {
              if (j + k < m)
                sum += f[x][j] * s[too][k] + s[too][k] * s[x][j] +
                       s[x][j] * f[too][k];
              else
                sum += f[x][j] * s[too][k] + s[too][k] * s[x][j] * 2 +
                       s[x][j] * f[too][k];
            }
      f[x][0] += f[too][m - 1] + s[too][m - 1];
      s[x][0] += s[too][m - 1];
      for (int j = 0; j <= m - 2; j++)
        f[x][j + 1] += f[too][j], s[x][j + 1] += s[too][j];
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n - 1; i++) {
    int j, k;
    scanf("%d %d", &j, &k);
    addedge(j, k);
    addedge(k, j);
  }
  dfs(1);
  printf("%I64d\n", sum);
  return 0;
}
