#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200042;
vector<int> G[MAXN];
long long Res[MAXN], Cnt[MAXN][5], Sum[MAXN][5];
bool visited[MAXN];
int n, k;
long long dfs(int w) {
  Res[w] = 0;
  visited[w] = true;
  long long tCnt[5], tSum[5];
  for (int i = (0); i <= ((int)k - 1); ++i) {
    tCnt[i] = 0;
    tSum[i] = 0;
  }
  tCnt[0] = 1;
  for (int i = (0); i <= ((int)G[w].size() - 1); ++i) {
    int u = G[w][i];
    if (!visited[u]) {
      dfs(u);
      Res[w] += Res[u];
      for (int l = (0); l <= ((int)k - 1); ++l) {
        for (int r = (0); r <= ((int)k - 1); ++r) {
          long long val =
              tSum[l] * Cnt[u][r] + tCnt[l] * Sum[u][r] + tCnt[l] * Cnt[u][r];
          if (((l + r + 1) % k) != 0) {
            val += (k - ((l + r + 1) % k)) * tCnt[l] * Cnt[u][r];
          }
          Res[w] += (val / k);
        }
      }
      for (int j = (0); j <= ((int)k - 1); ++j) {
        tCnt[(j + 1) % k] += Cnt[u][j];
        tSum[(j + 1) % k] += Sum[u][j] + Cnt[u][j];
      }
    }
  }
  for (int i = (0); i <= ((int)k - 1); ++i) {
    Cnt[w][i] = tCnt[i];
    Sum[w][i] = tSum[i];
  }
  return Res[w];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = (0); i <= ((int)n - 1 - 1); ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  cout << dfs(0) << "\n";
  return 0;
}
