#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, M = 5;
int cc[N][M], sz[N], k;
long long ret[N], sum = 0;
vector<int> adj[N];
long long dfs(int x, int p) {
  int t, v, j, u, i;
  sz[x] = 1;
  long long R = 0, temp;
  for (i = 0; i < adj[x].size(); ++i) {
    u = adj[x][i];
    if (u != p) {
      temp = dfs(u, x);
      sum += sz[u] * R;
      R += temp;
      sum += temp * sz[x];
      for (j = 0; j < k; ++j)
        for (t = 0; t < k; ++t) {
          if (j + t + 2 <= k) sum -= (long long)cc[x][j] * cc[u][t];
        }
      for (j = 0; j < k; ++j) cc[x][j] += cc[u][j];
      sz[x] += sz[u];
    }
  }
  u = ++cc[x][k - 1];
  for (i = k - 2; i >= 0; --i) cc[x][i + 1] = cc[x][i];
  cc[x][0] = u;
  ret[x] = R + u;
  return ret[x];
}
int main() {
  int n, i, j, u, v, a, b;
  cin >> n >> k;
  for (i = 0; i < n - 1; ++i) {
    scanf("%d%d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(1, 0);
  cout << sum << endl;
}
