#include <bits/stdc++.h>
using namespace std;
vector<int> edges[200001];
int subtree_size[200001];
int sz[200001][5];
int n, k;
long long ans, ansk[5];
void dfs(int t, int p) {
  subtree_size[t] = 1;
  int sz_accu[k];
  memset(sz_accu, 0, k * sizeof(int));
  memset(sz[t], 0, k * sizeof(int));
  sz[t][0]++;
  for (size_t i = 0; i < edges[t].size(); i++)
    if (edges[t][i] != p) {
      dfs(edges[t][i], t);
      for (int ia = 0; ia < k; ia++) {
        for (int ib = 0; ib < k; ib++) {
          int ic = (ia + ib + 2) % k;
          ansk[ic] += 1LL * sz_accu[ia] * sz[edges[t][i]][ib];
        }
      }
      for (int j = 0; j < k; j++) sz_accu[j] += sz[edges[t][i]][j];
      for (int j = 0; j < k; j++) {
        sz[t][(j + 1) % k] += sz[edges[t][i]][j];
        ansk[(j + 1) % k] += sz[edges[t][i]][j];
      }
    }
  subtree_size[p] += subtree_size[t];
  ans += 1LL * subtree_size[t] * (n - subtree_size[t]);
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  ans = 0;
  memset(ansk, 0, k * sizeof(long long));
  dfs(1, -1);
  for (int i = 1; i < k; i++) ans += (k - i) * ansk[i];
  cout << ans / k << endl;
  return 0;
}
