#include <bits/stdc++.h>
using namespace std;
int const N = 2e5 + 41;
int const M = 5;
int n, K;
vector<int> e[N];
vector<long long> cnt[N][M], sum[N][M];
long long ans = 0;
long long tmp[M];
void read() {
  scanf("%d %d", &n, &K);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    --u;
    --v;
    e[u].push_back(v);
    e[v].push_back(u);
  }
}
void dfs(int u, int p) {
  if (u == p) e[u].push_back(u);
  for (int i = 0; i < e[u].size(); ++i) {
    int to = e[u][i];
    if (to == p) {
      swap(e[u][i], e[u][0]);
      continue;
    }
    dfs(to, u);
  }
}
void rec(int u, int p) {
  for (int i = 0; i < K; ++i) {
    cnt[u][i].resize(e[u].size());
    sum[u][i].resize(e[u].size());
  }
  cnt[u][0][0] = 1;
  for (int i = 1; i < e[u].size(); ++i) {
    int to = e[u][i];
    rec(to, u);
    for (int kb = 0; kb < K; ++kb) {
      for (int kc = 0; kc < K; ++kc) {
        long long cb = cnt[u][kb][i - 1];
        long long cc = cnt[to][kc][e[to].size() - 1];
        long long sb = sum[u][kb][i - 1];
        long long sc = sum[to][kc][e[to].size() - 1];
        long long add = (kb + kc) / K;
        if ((kb + kc) % K) ++add;
        ans += cb * sc;
        ans += cc * sb;
        ans += add * cb * cc;
      }
    }
    for (int j = 0; j < K; ++j) {
      cnt[u][j][i] = cnt[u][j][i - 1] + cnt[to][j][e[to].size() - 1];
      sum[u][j][i] = sum[u][j][i - 1] + sum[to][j][e[to].size() - 1];
    }
  }
  for (int i = 0; i < K; ++i) {
    tmp[i] = sum[u][(i - 1 + K) % K][e[u].size() - 1];
    if (i == 0) {
      tmp[i] += cnt[u][(i - 1 + K) % K][e[u].size() - 1];
    }
  }
  for (int i = 0; i < K; ++i) {
    sum[u][i][e[u].size() - 1] = tmp[i];
  }
  for (int i = 0; i < K; ++i) {
    tmp[i] = cnt[u][(i - 1 + K) % K][e[u].size() - 1];
  }
  for (int i = 0; i < K; ++i) {
    cnt[u][i][e[u].size() - 1] = tmp[i];
  }
}
void solve() {
  dfs(0, 0);
  rec(0, 0);
  printf("%lld\n", ans);
}
int main() {
  read();
  solve();
  return 0;
}
