#include <bits/stdc++.h>
using namespace ::std;
const int maxn = 2e5 + 5;
int n, k;
long long ans, cnt[maxn][5], dp[maxn][5];
vector<vector<int> > g;
void dfs(int u, int fa) {
  cnt[u][0] = 1;
  for (int v : g[u]) {
    if (v == fa) continue;
    dfs(v, u);
    for (int i = 0; i < k; i++)
      for (int j = 0; j < k; j++) {
        ans +=
            cnt[u][i] * cnt[v][j] + cnt[u][i] * dp[v][j] + cnt[v][j] * dp[u][i];
        if (i + j + 1 > k) {
          ans += cnt[u][i] * cnt[v][j];
        }
      }
    for (int i = 1; i < k; i++) {
      dp[u][i] += dp[v][i - 1];
      cnt[u][i] += cnt[v][i - 1];
    }
    dp[u][0] += dp[v][k - 1] + cnt[v][k - 1];
    cnt[u][0] += cnt[v][k - 1];
  }
}
void solve() {
  scanf("%d%d", &n, &k);
  g.resize(n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(0, -1);
  printf("%lld\n", ans);
}
int main() {
  solve();
  return 0;
}
