#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
long long f[maxn][10], g[maxn][10], n, res, k, rres[maxn], rvres[maxn],
    f1[maxn];
vector<int> adj[maxn];
void dfs(int u, int p) {
  for (int i = 0; i < adj[u].size(); ++i) {
    int v = adj[u][i];
    if (v == p) continue;
    dfs(v, u);
    for (int j = 0; j < k; ++j) f[u][j + 1] += f[v][j];
    rres[u] += rres[v] + 1;
    rres[u] += f[v][k];
    f[u][1] += f[v][k];
  }
  f[u][0] = 1;
}
void dfs2(int u, int p) {
  for (int i = 0; i < adj[u].size(); ++i) {
    int v = adj[u][i];
    if (v == p) continue;
    for (int j = 0; j < k; ++j) {
      g[v][j + 1] += g[u][j] + f[u][j];
      if (j > 0) g[v][j + 1] -= f[v][j - 1];
      if (j == 1) g[v][j + 1] -= f[v][k];
    }
    rvres[v] += rvres[u] + rres[u] - rres[v] - 1 - f[v][k] + 1;
    rvres[v] += g[u][k] + f[u][k] - f[v][k - 1];
    g[v][1] += g[u][k] + f[u][k] - f[v][k - 1];
    dfs2(v, u);
  }
}
void dfs1(int u, int p) {
  f1[u] = 1;
  for (int i = 0; i < adj[u].size(); ++i) {
    int v = adj[u][i];
    if (v == p) continue;
    dfs1(v, u);
    f1[u] += f1[v];
  }
  res += f1[u] * (n - f1[u]);
}
int main() {
  cin >> n >> k;
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  if (k == 1) {
    dfs1(1, 0);
    cout << res;
    return 0;
  }
  dfs(1, 0);
  dfs2(1, 0);
  for (int i = 1; i <= n; ++i) res += rres[i] + rvres[i];
  cout << res / 2;
}
