#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<vector<int>> g(200001, vector<int>());
vector<int> subtree(200001, 0);
vector<vector<int>> subtree_mod(200001, vector<int>(5, 0));
long long ans;
void DFS(const int& u, const int& depth, const int& p) {
  subtree[u] = 1;
  subtree_mod[u][depth % k] = 1;
  for (int v : g[u]) {
    if (v == p) {
      continue;
    }
    DFS(v, depth + 1, u);
    for (int i = 0; i < k; ++i) {
      for (int j = 0; j < k; ++j) {
        int length = ((i + j - 2 * depth) % k + k) % k;
        int diff_to_k = ((k - length) % k + k) % k;
        ans += 1LL * diff_to_k * subtree_mod[u][i] * subtree_mod[v][j];
      }
    }
    for (int i = 0; i < k; ++i) {
      subtree_mod[u][i] += subtree_mod[v][i];
    }
    subtree[u] += subtree[v];
  }
  ans += 1LL * subtree[u] * (n - subtree[u]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  DFS(1, 0, -1);
  cout << ans / k << endl;
  return 0;
}
