#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000;
const int MOD = 1000 * 1000 * 1000 + 7;
const long INF_L = 1000 * 1000 * 1000;
const long long INF_LL = 1LL * INF_L * INF_L;
const long long MOD_LL = 1000000000007LL;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
long long pow(long long n, long long a, long long mod) {
  long long res = 1;
  while (a) {
    if (a & 1) res = (res * n) % mod;
    n = (n * n) % mod;
    a >>= 1;
  }
  return res;
}
long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
const int N = 200 * 1000 + 10;
const int M = 4000;
const int MAX_K = 5;
pair<long long, long long> d[N][MAX_K];
long long ans;
void dfs(int v, int p, const vector<vector<int>> &t, int k) {
  vector<pair<long long, long long>> tmp(k, make_pair(0, 0));
  for (int i = 0; i < t[v].size(); ++i) {
    int son = t[v][i];
    if (p != son) {
      dfs(son, v, t, k);
      for (int j1 = 0; j1 < k; ++j1) {
        for (int j2 = 0; j2 < k; ++j2) {
          ans +=
              tmp[j1].first * (d[son][j2].second) +
              tmp[j1].second * (d[son][j2].first) +
              ((j1 + j2 + 1 + k - 1) / k) * (tmp[j1].first * d[son][j2].first);
        }
        ans += tmp[j1].second + ((j1 + 1 + k - 1) / k) * (tmp[j1].first);
      }
      for (int j = 0; j < k; ++j) {
        d[v][(j + 1) % k].first += d[son][j].first;
        d[v][(j + 1) % k].second +=
            d[son][j].second + (j + 1 >= k ? d[son][j].first : 0);
        tmp[(j + 1) % k].first += d[son][j].first;
        tmp[(j + 1) % k].second +=
            d[son][j].second + (j + 1 >= k ? d[son][j].first : 0);
      }
      d[v][1 % k].first += 1;
      tmp[1 % k].first += 1;
      if (k == 1) {
        d[v][0].second += 1;
        tmp[0].second += 1;
      }
    }
  }
  for (int i = 0; i < k; ++i) {
    ans += (d[v][i].second + (i ? 1 : 0) * d[v][i].first);
  }
}
int main() {
  int n, k, u, v;
  cin >> n >> k;
  vector<vector<int>> t(n);
  for (int i = 0; i < n - 1; ++i) {
    cin >> u >> v;
    --u;
    --v;
    t[u].emplace_back(v);
    t[v].emplace_back(u);
  }
  dfs(0, -1, t, k);
  cout << ans << endl;
  return 0;
}
