#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2;
int n, k, childs[N];
pair<int, int> edges[N];
vector<vector<int> > g(N);
long long a[N][6], ans;
int countChilds(int i, int p) {
  childs[i] = 1;
  for (int j : g[i])
    if (j != p) childs[i] += countChilds(j, i);
  return childs[i];
}
void dfs(int i, int p, int d) {
  ++a[i][d % k];
  for (int j : g[i])
    if (j != p) {
      dfs(j, i, d + 1);
      for (int x = (0); x <= (int)(k - 1); ++x)
        for (int y = (0); y <= (int)(k - 1); ++y) {
          int z = ((x + y - 2 * d) % k + k) % k;
          if (z) ans += a[i][x] * a[j][y] * (k - z);
        }
      for (int x = (0); x <= (int)(k - 1); ++x) a[i][x] += a[j][x];
    }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = (1); i <= (int)(n - 1); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
    edges[i] = make_pair(x, y);
  }
  countChilds(1, 1);
  for (int i = (1); i <= (int)(n - 1); ++i) {
    int mn = min(childs[edges[i].first], childs[edges[i].second]);
    ans += 1ll * mn * (n - mn);
  }
  dfs(1, 1, 0);
  cout << ans / k;
}
