#include <bits/stdc++.h>
using namespace std;
struct rast {
  long long int r[6], k;
  rast() {
    k = 0;
    for (int i = 1; i < 6; i++) {
      r[i] = 0;
    }
    r[0] = 1;
  }
};
int n, k;
vector<vector<int> > a;
long long int ans;
rast r[202345];
void Add(int v, int to) {
  for (int i = 0; i <= k; i++) {
    ans += (r[v].k * r[to].r[i]) + (r[to].k * r[v].r[i]);
    for (int u = 0; u <= k; u++) {
      if (i + u < k)
        ans += r[v].r[i] * r[to].r[u];
      else if (i + u < k * 2)
        ans += 2 * r[v].r[i] * r[to].r[u];
      else
        ans += 3 * r[v].r[i] * r[to].r[u];
    }
  }
  for (int i = 0; i < k; i++) {
    r[v].r[i + 1] += r[to].r[i];
  }
  r[v].r[1] += r[to].r[k];
  r[v].k += r[to].k + r[to].r[k];
}
void dfs(int v, int from) {
  for (int i = 0; i < a[v].size(); i++) {
    int to = a[v][i];
    if (to == from) continue;
    dfs(to, v);
    Add(v, to);
  }
}
int main() {
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  dfs(0, -1);
  cout << ans << "\n";
  return 0;
}
