#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
long long dp[N][5];
long long DP[N];
int head[N], nex[N * 2], to[N * 2], tot = 0;
int n, k;
long long ans = 0;
void add(int u, int v) {
  to[++tot] = v;
  nex[tot] = head[u];
  head[u] = tot;
}
void dfs(int u, int fa, int d) {
  DP[u] = dp[u][d % k] = 1;
  for (int i = head[u]; i > 0; i = nex[i]) {
    int v = to[i];
    if (v == fa) continue;
    dfs(v, u, d + 1);
    for (int j = 0; j < k; j++) {
      for (int l = 0; l < k; l++) {
        ans += (k - (j - d + l - d) % k) % k * dp[u][j] * dp[v][l];
      }
    }
    for (int i = 0; i < k; i++) dp[u][i] += dp[v][i];
    ans += ((long long)n - DP[v]) * DP[v];
    DP[u] += DP[v];
  }
}
int main() {
  while (~scanf("%d%d", &n, &k)) {
    memset(head, 0, sizeof(head));
    memset(dp, 0, sizeof(dp));
    memset(DP, 0, sizeof(DP));
    tot = 0;
    for (int i = 1; i < n; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      add(u, v);
      add(v, u);
    }
    ans = 0;
    dfs(1, 0, 0);
    printf("%lld\n", ans / k);
  }
  return 0;
}
