#include <bits/stdc++.h>
struct link {
  link *nxt;
  int p;
};
const int N = 200000 + 10, K = 5 + 2;
int n, k;
long long ans, f[N][K], g[N];
link poool[N << 1], *pool = poool, *head[N];
inline void connect(int u, int v) {
  pool->p = v, pool->nxt = head[u], head[u] = pool++;
}
inline void dplink(int p, int s) {
  for (int i = 0; i < k - 1; ++i) f[p][i + 1] += f[s][i];
  g[p] += g[s] + f[s][k - 1], f[p][0] += f[s][k - 1];
}
inline void undplink(int p, int s) {
  for (int i = 0; i < k - 1; ++i) f[p][i + 1] -= f[s][i];
  g[p] -= g[s] + f[s][k - 1], f[p][0] -= f[s][k - 1];
}
inline void revlink(int p, int s) { undplink(p, s), dplink(s, p); }
void dfs1(int p, int fa) {
  f[p][0] = 1;
  for (link *e = head[p]; e; e = e->nxt)
    if (e->p != fa) dfs1(e->p, p), dplink(p, e->p);
}
void dfs2(int p, int fa) {
  for (int i = 1; i < k; ++i) ans += f[p][i];
  ans += g[p];
  for (link *e = head[p]; e; e = e->nxt)
    if (e->p != fa) revlink(p, e->p), dfs2(e->p, p), revlink(e->p, p);
}
int main(void) {
  scanf("%d %d", &n, &k);
  for (int i = 2, u, v; i <= n; ++i)
    scanf("%d %d", &u, &v), connect(u, v), connect(v, u);
  dfs1(1, 0), dfs2(1, 0), printf("%lld\n", ans >> 1);
}
