#include <bits/stdc++.h>
using namespace std;
int cnt = -1, head[200010];
struct Edge {
  int to, nxt;
} e[200010 << 1];
int n, k;
long long dp[200010][10], size[200010], ans;
void adde(int u, int v) {
  e[++cnt].to = v;
  e[cnt].nxt = head[u];
  head[u] = cnt;
  e[++cnt].to = u;
  e[cnt].nxt = head[v];
  head[v] = cnt;
}
void dfs(int u, int fa, int dep) {
  size[u] = dp[u][dep % k] = 1;
  for (int i = head[u]; ~i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fa) continue;
    dfs(v, u, dep + 1);
    for (int a = 0; a < k; a++)
      for (int b = 0; b < k; b++) {
        int dis = ((a + b) % k - (dep * 2) % k + k) % k;
        ans += ((k - dis) % k) * dp[u][a] * dp[v][b];
      }
    for (int a = 0; a < k; a++) dp[u][a] += dp[v][a];
    ans += size[v] * (n - size[v]);
    size[u] += size[v];
  }
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d%d", &n, &k);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    adde(u, v);
  }
  dfs(1, 1, 0);
  printf("%I64d\n", ans / k);
  return 0;
}
