#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector<int> graph[N];
int n, k, f[N][5], sz[N];
long long ans;
void dfs(int u = 1, int p = 0, int d = 0) {
  f[u][d % k] = 1;
  sz[u] = 1;
  for (int v : graph[u]) {
    if (v == p) continue;
    dfs(v, u, d + 1);
    sz[u] += sz[v];
    for (int i = 0; i < k; i++) {
      for (int j = 0; j < k; j++) {
        int t = (k - ((i + j - 2 * d) % k + k) % k) % k;
        ans += 1ll * t * f[u][i] * f[v][j];
      }
    }
    for (int i = 0; i < k; i++) {
      f[u][i] += f[v][i];
    }
  }
  ans += 1ll * sz[u] * (n - sz[u]);
}
int main() {
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  dfs();
  cout << ans / k << '\n';
  return 0;
}
