#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
static bool constexpr dbg = 0;
ll constexpr NM = 2.1e5;
ll n, k;
vector<ll> adj[NM];
ll cnt[NM];
ll mc[NM][5];
ll sum;
ll constexpr root = 1;
void dfs1(ll c, ll p) {
  cnt[c] = 1;
  mc[c][0] = 1;
  for (auto a : adj[c])
    if (a != p) {
      dfs1(a, c);
      cnt[c] += cnt[a];
      for (ll i = 0; i < (ll)(k); ++i) mc[c][(i + 1) % k] += mc[a][i];
    }
  sum += 2 * cnt[c] * (n - cnt[c]);
}
void dfs2(ll c, ll p) {
  ll pa[5] = {0};
  if (c != root) {
    for (ll i = 0; i < (ll)(k); ++i) pa[i] = mc[p][i] - mc[c][(i - 1 + k) % k];
    for (ll i = 0; i < (ll)(k); ++i)
      if ((i + 1) % k) sum += (k - i - 1) * (pa[i] + mc[c][i]);
  }
  for (ll i = 0; i < (ll)(k); ++i) mc[c][(i + 1) % k] += pa[i];
  for (auto a : adj[c])
    if (a != p) {
      dfs2(a, c);
    }
}
int main() {
  if (!dbg) {
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
  cin >> n >> k;
  for (ll _ = 1; _ <= (ll)(n - 1); ++_) {
    ll x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs1(1, 0);
  dfs2(1, 0);
  cout << sum / k / 2 << endl;
  return 0;
}
