#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, k;
long long sum[N], f[N][6], ans = 0;
vector<int> v[N];
void dfs(int x, int fa, int dep) {
  f[x][dep % k] = sum[x] = 1;
  for (auto u : v[x]) {
    if (u == fa) continue;
    dfs(u, x, dep + 1);
    for (int i(0); i <= (k - 1); ++i)
      for (int j(0); j <= (k - 1); ++j) {
        int dis = ((i + j) % k - ((dep * 2) % k) + k) % k;
        int t = (2 * k - dis) % k;
        ans += t * f[x][i] * f[u][j];
      }
    for (int i(0); i <= (k - 1); ++i) f[x][i] += f[u][i];
    sum[x] += sum[u];
    ans += (n - sum[u]) * sum[u];
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i(1); i <= (n - 1); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1, 0, 0);
  printf("%lld\n", ans / k);
  return 0;
}
