#include <bits/stdc++.h>
const int N = 2e5 + 1;
long long t[5], g[N][5], r;
int i, j, x, y, n, c, z, s[5], fa[N], en[N * 2], nxt[N * 2], siz[N][5];
void dfs(int u, int p) {
  int i = fa[u], v;
  for (*siz[u] = 1; i; i = nxt[i])
    if (en[i] ^ p) dfs(en[i], u);
  memset(t, 0, 8 * c), memset(s, 0, 4 * c);
  for (i = fa[u]; i; i = nxt[i])
    if ((v = en[i]) ^ p) {
      for (x = 0; x < c; t[x] += g[v][x], ++x)
        for (y = 0; y < c; ++y) {
          z = (x - c) % c + (y - c) % c + 2;
          r += t[x] * siz[v][y] + g[v][y] * s[x] +
               1ll * (z < 0 ? z / c : (z + c - 1) / c) * siz[v][y] * s[x];
        }
      for (x = 0; x < c; ++x)
        s[x] += siz[v][x], siz[u][(x + 1) % c] += siz[v][x];
      for (x = 0; x < c; ++x) g[u][(x + 1) % c] += g[v][x] + !x * siz[v][x];
    }
  for (x = 0; x < c; ++x) r += g[u][x];
}
int main() {
  for (scanf("%d%d", &n, &c); ++x < n;) {
    scanf("%d%d", &i, &j);
    en[++y] = j, nxt[y] = fa[i], fa[i] = y;
    en[++y] = i, nxt[y] = fa[j], fa[j] = y;
  }
  dfs(1, i = 0), printf("%I64d", r);
}
