#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:259000000")
using namespace std;
void mkfile();
int solve();
int main() {
  srand(228);
  solve();
  return 0;
}
void mkfile() {
  freopen("input.txt", "a+", stdout);
  srand(time(0));
  return;
}
const long double EPS = 1e-9;
const long double pi = acos(-1.0);
bool equal(double a, double b) { return abs(a - b) < EPS; }
const int MAXN = (int)2e5 + 7;
const int INF = (int)1e9 + 7;
const long long LINF = (long long)7e18;
const long long MOD = (long long)1e9 + 7;
const int CHASH = (long long)239017;
const long double DINF = (long double)1000000000000000.0;
int n, k;
vector<int> g[MAXN];
int p[MAXN];
int d[MAXN];
int c[MAXN];
int cur = -1;
int cr;
vector<int> order;
int sz;
void dfscalc(int u, int pr) {
  p[u] = cur;
  d[u] = 1;
  for (auto to : g[u]) {
    if (to != pr && !c[to]) {
      dfscalc(to, u);
      d[u] += d[to];
    }
  }
}
int dfsmark(int u, int pr) {
  for (auto to : g[u]) {
    if (pr != to && !c[to]) {
      if (d[to] * 2 >= sz) return dfsmark(to, u);
    }
  }
  return u;
}
void getcent(int u, int pr) {
  cur = pr;
  dfscalc(u, pr);
  sz = d[u];
  int ncr = dfsmark(u, pr);
  c[ncr] = 1;
  order.push_back(ncr);
  p[ncr] = pr;
  for (auto to : g[ncr]) {
    if (to != ncr && !c[to]) getcent(to, ncr);
  }
}
long long ans;
int gid;
struct node {
  int id, dst, ost;
  node(){};
  node(int id, int dst, int ost) : id(id), dst(dst), ost(ost){};
};
struct infocmp {
  long long sz;
  long long sum;
  vector<int> ostcnt;
  infocmp() { ostcnt.resize(k), sum = 0, sz = 0; };
};
vector<vector<node> > cmp;
vector<infocmp> cstat;
void dfs(int u, int pr) {
  d[u] = d[pr] + 1;
  cmp[gid].push_back(node(u, (d[u] + k - 1) / k, d[u] % k));
  for (auto to : g[u]) {
    if (to != pr && !c[to]) dfs(to, u);
  }
}
void precalc(int u) {
  cmp.clear();
  cstat.clear();
  long long sumk = 0;
  long long cnt = 0;
  vector<long long> ost;
  ost.resize(k);
  gid = -1;
  d[u] = 0;
  for (auto to : g[u]) {
    if (c[to]) continue;
    ++gid;
    cmp.push_back({});
    cstat.push_back(infocmp());
    dfs(to, u);
    cstat[gid].sz = cmp[gid].size();
    cnt += (long long)cmp[gid].size();
    for (auto &v : cmp[gid]) {
      ++cstat[gid].ostcnt[v.ost];
      ++ost[v.ost];
      sumk += (long long)v.dst;
      cstat[gid].sum += (long long)v.dst;
    }
  }
  ans += sumk * 2ll;
  for (int i = 0; i <= gid; ++i) {
    sumk -= (long long)cstat[i].sum;
    cnt -= (long long)cstat[i].sz;
    for (int j = 0; j < k; ++j) ost[j] -= (long long)cstat[i].ostcnt[j];
    for (auto &v : cmp[i]) {
      long long res = sumk + (long long)v.dst * (long long)cnt;
      int oost = k - v.ost;
      oost %= k;
      if (oost != 0) {
        for (int j = 1; j <= oost; ++j) res -= (long long)ost[j];
      }
      ans += res;
    }
    sumk += (long long)cstat[i].sum;
    cnt += (long long)cstat[i].sz;
    for (int j = 0; j < k; ++j) ost[j] += (long long)cstat[i].ostcnt[j];
  }
}
int solve() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    --x, --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  getcent(0, -1);
  memset(c, 0, sizeof c);
  for (int i = 0; i < n; ++i) precalc(order[i]), c[order[i]] = 1;
  printf("%lld\n", ans / 2ll);
  return 0;
}
