#include <bits/stdc++.h>
using namespace std;
long long cnt_up[200100][6], cnt_children[200100][6], ans[200100];
int n, p;
vector<int> g[200100];
void dfs(int k, int prev) {
  for (int i = 0; i < g[k].size(); i++) {
    int to = g[k][i];
    if (to == prev) continue;
    dfs(to, k);
    long long jumps;
    for (int j = 1; j <= p; j++)
      for (int l = 1; l <= p; l++) {
        jumps = (long long)((j + l + p - 1) / p);
        ans[k] += cnt_up[k][j] * cnt_children[to][l - 1] +
                  cnt_children[k][j] * cnt_up[to][l - 1] +
                  jumps * cnt_children[k][j] * cnt_children[to][l - 1];
      }
    for (int j = 1; j <= p; j++)
      ans[k] += cnt_up[to][j - 1] + cnt_children[to][j - 1];
    for (int j = 1; j <= p; j++) cnt_up[k][j] += cnt_up[to][j - 1];
    for (int j = 1; j <= p; j++) cnt_children[k][j] += cnt_children[to][j - 1];
  }
  cnt_up[k][0] = cnt_up[k][p] + cnt_children[k][p];
  cnt_children[k][0] = cnt_children[k][p] + 1ll;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> p;
  int to, from;
  for (int i = 0; i < n - 1; i++) {
    cin >> to >> from;
    g[to].push_back(from);
    g[from].push_back(to);
  }
  dfs(1, 0);
  long long res = 0ll;
  for (int i = 1; i <= n; i++) res += ans[i];
  cout << res << endl;
  return 0;
}
