#include <bits/stdc++.h>
using namespace std;
struct ed {
  int u, nex;
} e[200010 * 2];
long long n, k0, fir[200010], st;
long long ans, jp[200010], s[200010][5], Jp[200010], S[200010][5];
void add(long long u, long long v) {
  e[++st].u = v;
  e[st].nex = fir[u];
  fir[u] = st;
  e[++st].u = u;
  e[st].nex = fir[v];
  fir[v] = st;
}
void dfs1(long long u, long long fa) {
  s[u][0] = 1;
  jp[u] = 0;
  for (long long i = fir[u]; i; i = e[i].nex) {
    long long v = e[i].u;
    if (v == fa) continue;
    dfs1(v, u);
    jp[u] += jp[v];
    for (long long k = 0; k < k0; k++) s[u][k] += s[v][(k - 1 + k0) % k0];
    jp[u] += s[v][0];
  }
}
void dfs2(long long u, long long fa) {
  if (u != 1) {
    for (long long k = 0; k < k0; k++) {
      S[u][k] = S[fa][(k - 1 + k0) % k0];
      S[u][k] = S[u][k] - s[u][(k - 2 + k0) % k0] + s[u][k];
    }
    Jp[u] = Jp[fa];
    Jp[u] += (S[fa][0] - s[u][k0 - 1]);
    Jp[u] -= s[u][0];
  }
  ans += Jp[u];
  for (long long i = fir[u]; i; i = e[i].nex) {
    long long v = e[i].u;
    if (v == fa) continue;
    dfs2(v, u);
  }
}
int main() {
  cin >> n >> k0;
  for (int i = 1, u, v; i < n; i++) cin >> u >> v, add(u, v);
  dfs1(1, 0);
  memcpy(S, s, sizeof(s));
  Jp[1] = jp[1];
  dfs2(1, 0);
  cout << ans / 2 << endl;
}
