#include <bits/stdc++.h>
using namespace std;
const int mx = 2e5 + 10;
const int mod = 1e9 + 7;
int n, k;
vector<int> vec[mx];
long long sum[mx][5], cnt[mx][5], ans;
void dfs(int u, int fa) {
  sum[u][0] = 0, cnt[u][0] = 1;
  for (int v : vec[u]) {
    if (v != fa) {
      dfs(v, u);
      for (int i = 0; i < k; ++i) {
        int id = (i - 1 + k) % k;
        sum[u][i] += sum[v][id];
        if (i == 0) sum[u][i] += cnt[v][id];
        cnt[u][i] += cnt[v][id];
      }
    }
  }
}
void dfs2(int u, int fa) {
  for (int i = 0; i < k; ++i) ans += sum[u][i] + (i ? cnt[u][i] : 0);
  for (int v : vec[u]) {
    if (v != fa) {
      long long tp[4][k];
      for (int i = 0; i < k; ++i) {
        tp[0][i] = sum[u][i];
        tp[1][i] = cnt[u][i];
        tp[2][i] = sum[v][i];
        tp[3][i] = cnt[v][i];
      }
      for (int i = 0; i < k; ++i) {
        int id = (i - 1 + k) % k;
        sum[u][i] -= sum[v][id];
        if (i == 0) sum[u][i] -= cnt[v][id];
        cnt[u][i] -= cnt[v][id];
      }
      for (int i = 0; i < k; ++i) {
        int id = (i - 1 + k) % k;
        sum[v][i] += sum[u][id];
        if (i == 0) sum[v][i] += cnt[u][id];
        cnt[v][i] += cnt[u][id];
      }
      dfs2(v, u);
      for (int i = 0; i < k; ++i) {
        sum[u][i] = tp[0][i], cnt[u][i] = tp[1][i];
        sum[v][i] = tp[2][i], cnt[v][i] = tp[3][i];
      }
    }
  }
}
int main() {
  int u, v;
  scanf("%d%d", &n, &k);
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &u, &v);
    vec[u].push_back(v), vec[v].push_back(u);
  }
  dfs(1, 0);
  dfs2(1, 0);
  printf("%lld\n", ans / 2);
}
