#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
int n, k;
ll res;
const int MAX = 2e5 + 10;
ll s[MAX][5];
ll q[MAX][5];
vi e[MAX];
int v[MAX];
void dfs(int x) {
  v[x] = 1;
  q[x][0] += 1;
  for (int y : e[x]) {
    if (v[y]) continue;
    dfs(y);
    for (int i = 0; i < k; i++) {
      for (int j = 0; j < k; j++) {
        res += s[x][i] * q[y][j];
        res += s[y][j] * q[x][i];
        int c1 = (i + j + 1) / k;
        if ((i + j + 1) % k) c1++;
        int c2 = i / k + j / k;
        if (i % k) c2++;
        if (j % k) c2++;
        res += q[x][i] * q[y][j] * (c1 - c2);
      }
    }
    for (int i = 0; i < k; i++) {
      q[x][(i + 1) % k] += q[y][i];
      s[x][(i + 1) % k] += s[y][i];
    }
    s[x][1 % k] += q[y][0];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  dfs(1);
  cout << res << "\n";
}
