#include <bits/stdc++.h>
using namespace std;
const long long nax = 2e5 + 100;
vector<long long> g[nax];
long long d[nax], n, k, res, par[nax][5];
void dfs(long long s, long long p) {
  par[s][0]++;
  d[s] = 1;
  for (auto it : g[s]) {
    if (it == p) continue;
    dfs(it, s);
    for (long long i = 0; i < k; i++)
      for (long long j = 0; j < k; j++) {
        long long used = (k - (i + j + 1) % k) % k;
        long long ans = (par[s][i] * par[it][j]) * used;
        res += ans;
      }
    for (long long i = 0; i < k; i++) par[s][(i + 1) % k] += par[it][i];
    d[s] += d[it];
  }
  res += d[s] * (n - d[s]);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  res = 0;
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) g[i].clear();
  for (long long i = 1, x, y; i < n; i++) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, 0);
  cout << (res / k);
  return 0;
}
