#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 30;
vector<int> v[maxn];
int n, k;
long long ans = 0, dp[maxn][5], h[maxn];
void dfs(int cur, int pre, int d) {
  h[cur] = 1;
  dp[cur][d % k] = 1;
  for (auto to : v[cur]) {
    if (to == pre) continue;
    dfs(to, cur, d + 1);
    for (int i = 0; i < k; ++i) {
      for (int j = 0; j < k; ++j) {
        int x = (i + j - d * 2) % k;
        int y = (k - x) % k;
        ans += y * dp[cur][i] * dp[to][j];
      }
    }
    for (int i = 0; i < k; ++i) dp[cur][i] += dp[to][i];
    ans += (n - h[to]) * h[to];
    h[cur] += h[to];
  }
}
int main() {
  int a, b;
  scanf("%d%d", &n, &k);
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(1, 0, 0);
  printf("%lld\n", ans / k);
  return 0;
}
