#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
bool umin(T1& x, const T2& y) {
  return (x > y ? (x = y, true) : false);
}
template <typename T1, typename T2>
bool umax(T1& x, const T2& y) {
  return (x < y ? (x = y, true) : false);
}
template <typename T>
void read(T& x) {
  char ch;
  T p = 1;
  x = 0;
  do {
    ch = getchar();
  } while (ch <= ' ');
  if (ch == '-') p = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= p;
}
void read(string& x) {
  char ch;
  do {
    ch = getchar();
  } while (ch <= ' ');
  while (ch > ' ') x += ch, ch = getchar();
}
void read(char& x) {
  do {
    x = getchar();
  } while (x <= ' ');
}
template <typename T, typename... R>
void read(T& x, R&... y) {
  read(x);
  read(y...);
}
const int N = (int)1e6 + 3;
const long long mod = (long long)1e9 + 7;
const int INF = (int)1e9 + 17;
const long long LLINF = (long long)1e18 + 17;
const long double pi = (long double)acos(-1.0);
int n, m;
int sz[N];
long long cnt[8];
long long addcnt[8];
long long res;
long long add[8], sum[8];
bool used[N];
vector<int> g[N];
int dfs(int v, int p) {
  sz[v] = 1;
  for (int to : g[v]) {
    if (to == p || used[to]) continue;
    sz[v] += dfs(to, v);
  }
  return sz[v];
}
int findCentriod(int v) {
  bool run = true;
  int N = sz[v], p = -1;
  while (run) {
    run = false;
    for (int to : g[v]) {
      if (to == p || used[to]) continue;
      if (sz[to] > N / 2) {
        p = v;
        v = to;
        run = true;
        break;
      }
    }
  }
  return v;
}
void go(int v, int p, int d) {
  add[d % m] += d / m;
  addcnt[d % m]++;
  long long was = res;
  for (int i = (0); i < (m); i++) {
    res += sum[i] + cnt[i] * (d / m);
    if (i + (d % m) == 0) continue;
    if (i + (d % m) <= m) res += cnt[i];
    if (i + (d % m) > m) res += 2 * cnt[i];
  }
  for (int to : g[v]) {
    if (to == p || used[to]) continue;
    go(to, v, d + 1);
  }
}
void solve(int v) {
  dfs(v, -1);
  v = findCentriod(v);
  fill(sum, sum + m + 1, 0);
  fill(cnt, cnt + m + 1, 0);
  cnt[0] = 1;
  for (int to : g[v]) {
    if (used[to]) continue;
    fill(add, add + m + 1, 0);
    fill(addcnt, addcnt + m + 1, 0);
    go(to, v, 1);
    for (int i = (0); i < (m); i++) sum[i] += add[i], cnt[i] += addcnt[i];
  }
  used[v] = true;
  for (int to : g[v])
    if (!used[to]) solve(to);
}
int main() {
  read(n, m);
  for (int i = (1); i < (n); i++) {
    int x, y;
    read(x, y);
    --x, --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  solve(0);
  printf("%I64d\n", res);
  return 0;
}
