#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int K = 7;
vector<int> g[N];
long long dp[N][K], cnt[N][K], sol;
int n, k;
void unite(int v, int xt) {
  for (int i = 0; i < k; i++) {
    if (cnt[xt][i] == 0) continue;
    for (int j = 0; j < k; j++) {
      if (cnt[v][j] == 0) continue;
      long long y = (i + 1 + j) % k;
      if (y == 0) y = k;
      long long add = k - y;
      sol += (dp[xt][i] * cnt[v][j] + dp[v][j] * cnt[xt][i] +
              (add + 1) * cnt[xt][i] * cnt[v][j]) /
             k;
    }
  }
}
void dfs(int v, int prev) {
  cnt[v][0] = 1;
  for (auto xt : g[v]) {
    if (xt == prev) continue;
    dfs(xt, v);
    unite(v, xt);
    for (int i = 0; i < k; i++) {
      dp[v][(i + 1) % k] += dp[xt][i] + cnt[xt][i];
      cnt[v][(i + 1) % k] += cnt[xt][i];
    }
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1, 0);
  printf("%lld", sol);
  return 0;
}
