#include <bits/stdc++.h>
const long long N = 5e5 + 100;
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
long long n, k;
struct edge {
  long long next, to, w;
} e[N << 1];
long long head[N], cnt;
inline void add(long long x, long long y) {
  e[++cnt].next = head[x];
  e[cnt].to = y;
  e[cnt].w = 1;
  head[x] = cnt;
}
long long ans, f[N][10], dis[N];
inline void dfs(long long x, long long fa, long long d) {
  dis[x] = 1;
  f[x][d % k] = 1;
  for (long long i = head[x]; i; i = e[i].next) {
    long long y = e[i].to;
    if (y == fa) continue;
    dfs(y, x, d + 1);
    for (long long j = 0; j < k; j++) {
      for (long long p = 0; p < k; p++) {
        long long u = (p + j - 2 * d) % k;
        long long v = (k - u) % k;
        ans += v * f[x][j] * f[y][p];
      }
    }
    for (long long j = 0; j < k; j++) f[x][j] += f[y][j];
    ans += (n - dis[y]) * dis[y];
    dis[x] += dis[y];
  }
}
signed main() {
  n = read(), k = read();
  for (long long i = 1; i < n; i++) {
    long long u, v;
    u = read();
    v = read();
    add(u, v);
    add(v, u);
  }
  dfs(1, 0, 0);
  printf("%lld", ans / k);
}
