#include <bits/stdc++.h>
int n, k;
int sz[(200010)], dp[(200010)][(5)];
long long ans, cnt[(5)];
std::vector<int> vec[(200010)];
void dfs(int u, int fa) {
  sz[u] = 1;
  dp[u][0] = 1;
  long long sum[(5)] = {0};
  for (auto v : vec[u]) {
    if (v == fa) continue;
    dfs(v, u);
    sz[u] += sz[v];
    ans += 1ll * sz[v] * (n - sz[v]);
    for (int i = 0; i < k; ++i) {
      dp[u][(i + 1) % k] += dp[v][i];
      for (int j = 0; j < k; ++j) {
        cnt[(i + j + 2) % k] += sum[i] * dp[v][j];
      }
      cnt[(i + 1) % k] += dp[v][i];
    }
    for (int i = 0; i < k; ++i) {
      sum[i] += dp[v][i];
    }
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    vec[u].push_back(v);
    vec[v].push_back(u);
  }
  dfs(1, 0);
  for (int i = 1; i < k; ++i) {
    ans += i * cnt[k - i];
  }
  printf("%I64d\n", ans / k);
  return 0;
}
