#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, k;
long long f[N][5], siz[N];
vector<int> to[N];
void link(int now, int v) {
  siz[now] += siz[v];
  for (int i = 1; i < k; i++) f[now][i] += f[v][i - 1];
  f[now][0] += f[v][k - 1] + siz[v];
}
void cut(int now, int v) {
  siz[now] -= siz[v];
  for (int i = 1; i < k; i++) f[now][i] -= f[v][i - 1];
  f[now][0] -= f[v][k - 1] + siz[v];
}
void dfs_pre(int now, int fa) {
  siz[now] = 1;
  for (auto v : to[now]) {
    if (v == fa) continue;
    dfs_pre(v, now);
    link(now, v);
  }
}
long long ans = 0;
void solve(int now, int fa) {
  ans += f[now][0];
  for (auto v : to[now]) {
    if (v == fa) continue;
    cut(now, v);
    link(v, now);
    solve(v, now);
    cut(v, now);
    link(now, v);
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1, x, y; i < n; i++) {
    scanf("%d%d", &x, &y);
    to[x].push_back(y);
    to[y].push_back(x);
  }
  dfs_pre(1, 0);
  solve(1, 0);
  printf("%lld\n", ans / 2);
  return 0;
}
