#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000;
vector<int> g[maxn];
int64_t res[maxn];
int64_t pres[maxn];
int sz[maxn];
int k;
int n;
int rsd[maxn][5];
void dfs(int v, int p) {
  res[v] = 0;
  pres[v] = 0;
  sz[v] = 1;
  rsd[v][0] = 1;
  for (int i = 1; i < k; ++i) rsd[v][i] = 0;
  for (int u : g[v]) {
    if (u == p) continue;
    dfs(u, v);
    res[v] += res[u];
    res[v] += pres[u] * 1LL * sz[v];
    res[v] += pres[v] * 1LL * sz[u];
    res[v] += rsd[v][0] * 1LL * rsd[u][0];
    for (int i = 1; i < k; ++i)
      for (int j = 1; j < k; ++j)
        if (i + j > k) res[v] -= rsd[v][i] * 1LL * rsd[u][j];
    sz[v] += sz[u];
    pres[v] += pres[u];
    for (int i = 1; i < k; ++i) {
      rsd[v][i - 1] += rsd[u][i];
    }
    pres[v] += rsd[u][0];
    rsd[v][k - 1] += rsd[u][0];
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i < n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0, -1);
  cout << res[0] << '\n';
  return 0;
}
