#include <bits/stdc++.h>
using namespace std;
int count_subtree[200005][5], tot_subtree[200005];
vector<int> adj[200005];
int n, k;
long long ans = 0;
inline void dfs(int c, int p, int d) {
  count_subtree[c][d % k] = tot_subtree[c] = 1;
  for (auto it : adj[c]) {
    if (it != p) {
      dfs(it, c, d + 1);
      for (int x = 0; x < k; x++)
        for (int y = 0; y < k; y++) {
          int rem = ((x + y) - (2 * d) + k) % k;
          int actual = (k - rem + k) % k;
          ans += 1LL * actual * count_subtree[c][x] * count_subtree[it][y];
        }
      for (int x = 0; x < k; x++) count_subtree[c][x] += count_subtree[it][x];
      tot_subtree[c] += tot_subtree[it];
    }
  }
  ans += 1LL * tot_subtree[c] * (n - tot_subtree[c]);
}
int main() {
  scanf("%d", &n);
  ;
  scanf("%d", &k);
  ;
  for (int x = 0; x < n - 1; x++) {
    int u, v;
    scanf("%d", &u);
    ;
    scanf("%d", &v);
    ;
    adj[u].emplace_back(v);
    adj[v].emplace_back(u);
  }
  dfs(1, 0, 0);
  ans /= k;
  printf("%lld", ans);
  ;
}
