#include <bits/stdc++.h>
const int ms = 200200;
int n, k;
std::vector<int> edges[ms];
long long dists[ms], distt[ms];
long long paths[ms][5];
long long tot[ms];
long long nxt[5];
long long top[ms][5];
long long wtf[5];
long long tot_dist = 0;
void dfs(int on, int par = -1) {
  paths[on][0]++;
  top[on][0]++;
  tot[on]++;
  for (int i = 0; i < edges[on].size(); i++) {
    int to = edges[on][i];
    if (to == par) continue;
    dfs(to, on);
    dists[on] +=
        ((distt[to]) * (tot[on])) + ((distt[on]) * tot[to]) + tot[to] * tot[on];
    distt[on] += distt[to] + tot[to];
    tot[on] += tot[to];
    for (int j = 0; j < k; j++) nxt[j] = paths[on][j];
    for (int j = 0; j < k; j++) {
      for (int jj = 0; jj < k; jj++) {
        nxt[(j + jj + 1) % k] += top[on][j] * top[to][jj];
      }
    }
    for (int j = 0; j < k; j++) paths[on][j] = nxt[j];
    for (int j = 0; j < k; j++) top[on][(j + 1) % k] += top[to][j];
  }
  for (int i = 0; i < k; i++) wtf[i] += paths[on][i];
  tot_dist += dists[on];
}
int main() {
  std::cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%i %i", &u, &v);
    edges[u].push_back(v);
    edges[v].push_back(u);
  }
  dfs(1);
  long long ans = tot_dist;
  for (int i = 1; i < k; i++) {
    ans += wtf[i] * (k - i);
  }
  ans /= k;
  std::cout << ans << '\n';
}
