#include <bits/stdc++.h>
using namespace std;
long long ans[200000], sum[200000][5], cnt[200000][5];
int n, m;
std::vector<int> e[200000];
void dfs(int u, int fa) {
  cnt[u][0] = 1;
  for (int v : e[u])
    if (v != fa) {
      dfs(v, u);
      for (int i = 0; i < m; ++i) {
        for (int j = 0; j < m; ++j) {
          ans[u] += cnt[u][i] * sum[v][j] + sum[u][i] * cnt[v][j];
          ans[u] += ((i + j + 1 + m - 1) / m) * cnt[u][i] * cnt[v][j];
        }
      }
      ans[u] += ans[v];
      for (int i = 1; i < m; ++i) {
        sum[u][i] += sum[v][(i + m - 1) % m];
      }
      sum[u][0] += sum[v][m - 1] + cnt[v][m - 1];
      for (int i = 0; i < m; ++i) {
        cnt[u][i] += cnt[v][(i + m - 1) % m];
      }
    }
}
int main(int argc, char const *argv[]) {
  cin >> n >> m;
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dfs(0, -1);
  cout << ans[0] << endl;
  return 0;
}
