#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 55;
vector<int> g[N];
int n, k;
long long answer = 0;
struct TResult {
  int arr[5] = {0};
  int size = 0;
  TResult() {}
};
TResult dfs(int u, int par) {
  TResult res = TResult();
  res.arr[0] = 1;
  res.size = 1;
  TResult cum = TResult();
  for (auto v : g[u]) {
    if (v != par) {
      TResult sres = dfs(v, u);
      res.size += sres.size;
      for (int i = 0; i < k; i++) {
        for (int j = 0; j < k; j++) {
          int need = ((k - ((i + j + 2) % k)) % k);
          answer += 1LL * need * cum.arr[i] * sres.arr[j];
        }
      }
      for (int i = 0; i < k; i++) {
        cum.arr[i] += sres.arr[i];
      }
    }
  }
  for (int i = 0; i < k; i++) {
    res.arr[(i + 1) % k] += cum.arr[i];
    answer += ((k - (i + 1)) % k) * res.arr[(i + 1) % k];
  }
  answer += 1LL * res.size * (n - res.size);
  return res;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, -1);
  cout << answer / k;
  return 0;
}
