#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
const int N = 200010;
int las[N], nxt[N << 1], to[N << 1], cnt;
inline void add(int u, int v) {
  cnt++;
  to[cnt] = v;
  nxt[cnt] = las[u];
  las[u] = cnt;
}
inline void add2() {
  static int a, b;
  scanf("%d%d", &a, &b);
  add(a, b);
  add(b, a);
}
int n, k;
long long a[N][7], ans;
void dfs1(int now, int la) {
  int i, j;
  a[now][1 % k] = 1;
  a[now][k] = 1;
  for (i = las[now]; i; i = nxt[i])
    if (to[i] != la) {
      dfs1(to[i], now);
      for (j = 0; j < k; j++) a[now][(j + 1) % k] += a[to[i]][j];
      a[now][k] += a[to[i]][k] + a[to[i]][0];
    }
}
inline void swap(long long &x, long long &y) { x ^= y ^= x ^= y; }
void dfs2(int now, int la) {
  int i, j;
  long long tmp;
  if (la) {
    for (i = 0; i <= k; i++) a[now][i] = a[la][i] - a[now][i];
    a[now][k] += a[now][0];
    tmp = a[now][k - 1];
    for (i = 0; i < k; i++) swap(a[now][i], tmp);
  } else
    for (i = 0; i <= k; i++) a[now][i] = 0;
  a[now][0]++;
  for (i = las[now]; i; i = nxt[i])
    if (to[i] != la)
      for (j = 0; j <= k; j++) a[now][j] += a[to[i]][j];
  ans += a[now][k];
  for (i = las[now]; i; i = nxt[i])
    if (to[i] != la) dfs2(to[i], now);
}
int main() {
  int i;
  scanf("%d%d", &n, &k);
  for (i = 1; i < n; i++) add2();
  dfs1(1, 0);
  dfs2(1, 0);
  printf("%lld\n", ans >> 1);
  return 0;
}
