#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
vector<int> adj[N];
long long pop[N];
long long full[N];
long long cnt[N][5];
long long ans = 0;
int n, k;
void dfs(int u, int par = -1) {
  pop[u] = 1;
  cnt[u][0] = 1;
  for (auto v : adj[u])
    if (v != par) {
      dfs(v, u);
      pop[u] += pop[v];
      full[u] += full[v];
      for (int i = 0; i < k; i++) cnt[u][(i + 1) % k] += cnt[v][i];
      full[u] += cnt[v][k - 1];
    }
  ans += full[u];
  for (int i = 1; i < k; i++) ans += cnt[u][i];
  long long tmp = 0;
  for (auto v : adj[u])
    if (v != par) {
      long long rest = pop[u] - pop[v] - 1;
      ans += rest * (full[v] + cnt[v][k - 1]);
      for (int i = 0; i < k; i++) {
        long long a = cnt[v][(i - 1 + k) % k];
        for (int j = 0; j < k; j++) {
          long long b = cnt[u][j] - cnt[v][(j - 1 + k) % k];
          if (j == 0) b--;
          if (i + j == 0) continue;
          if (i + j <= k)
            tmp += a * b;
          else
            tmp += 2 * a * b;
        }
      }
    }
  ans += tmp / 2;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    adj[x - 1].push_back(y - 1);
    adj[y - 1].push_back(x - 1);
  }
  dfs(0);
  cout << ans << endl;
}
