#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
namespace zkc {
const long long N = 200050;
long long n, k, head[N], tot;
bool vis[N];
long long cnt[N][8], sum[N], ans;
struct node {
  long long v, next;
} e[N << 1];
void insert(long long u, long long v) {
  e[++tot] = (node){v, head[u]};
  head[u] = tot;
  e[++tot] = (node){u, head[v]};
  head[v] = tot;
}
void dfs(long long u, long long f, long long dep) {
  cnt[u][dep % k] = sum[u] = 1;
  for (long long i = head[u]; i; i = e[i].next) {
    long long v = e[i].v;
    if (v == f) continue;
    dfs(v, u, dep + 1);
    for (long long j = 0; j < k; j++)
      for (long long p = 0; p < k; p++) {
        long long tmp = (k - (((j + p - 2 * dep) % k + k) % k)) % k;
        ans += tmp * cnt[u][j] * cnt[v][p];
      }
    for (long long j = 0; j < k; j++) cnt[u][j] += cnt[v][j];
    sum[u] += sum[v];
  }
  ans += sum[u] * (n - sum[u]);
}
inline void work() {
  n = read(), k = read();
  for (register long long i = 1; i <= n - 1; i++) {
    long long u = read();
    long long v = read();
    insert(u, v);
  }
  dfs(1, 0, 0);
  printf("%lld\n", ans / k);
  return;
}
}  // namespace zkc
int main() {
  zkc::work();
  return 0;
}
