#include <bits/stdc++.h>
using namespace std;
int n, k;
long long ans, dis[200050][6], siz[200050][6];
struct edge {
  int to, nex;
};
vector<edge> G;
int head[200050];
inline void addedge(int u, int v) {
  G.push_back((edge){v, head[u]});
  head[u] = G.size() - 1;
  G.push_back((edge){u, head[v]});
  head[v] = G.size() - 1;
}
void dfs(int u, int fa) {
  siz[u][0] = 1;
  for (int i = head[u]; ~i; i = G[i].nex) {
    int v = G[i].to;
    if (v == fa) continue;
    dfs(v, u);
    for (int j = 0; j < k; j++) {
      for (int h = 0; h < k; h++) {
        ans += siz[u][j] * dis[v][h];
        ans += siz[v][h] * dis[u][j];
        ans += (j + h + k) / k * siz[u][j] * siz[v][h];
      }
    }
    for (int j = 1; j < k; j++) {
      dis[u][j] += dis[v][j - 1];
      siz[u][j] += siz[v][j - 1];
    }
    dis[u][0] += dis[v][k - 1] + siz[v][k - 1];
    siz[u][0] += siz[v][k - 1];
  }
}
int main() {
  scanf("%d%d", &n, &k);
  memset(head, -1, sizeof(head));
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    addedge(u, v);
  }
  dfs(1, -1);
  printf("%lld\n", ans);
  return 0;
}
