#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 7;
const int M = 20;
const int inf = 1e9 + 7;
const long long linf = 1e18 + 7;
const double pi = acos(-1);
const double eps = 1e-7;
const bool multipleTest = 0;
long long f[N][6];
long long sum[N][6];
long long ans;
int n, k;
vector<int> adj[N];
long long g[6];
long long sl[6];
void dfs(int u, int r) {
  for (auto& v : adj[u]) {
    if (v != r) {
      dfs(v, u);
      for (int j = (1); j < (k); j++) {
        ans += sum[v][j];
        g[(j + 1) % k] = sum[v][j];
        sl[(j + 1) % k] = f[v][j];
      }
      g[1 % k] = sum[v][0] + f[v][0];
      sl[1 % k] = f[v][0];
      ans += g[1 % k];
      for (int j = (0); j < (k); j++) {
        for (int t = (0); t < (k); t++) {
          if (j == 0 || t == 0 || j + t > k) {
            ans += sum[u][j] * sl[t];
            ans += g[t] * f[u][j];
          } else {
            ans += sum[u][j] * sl[t];
            ans += g[t] * f[u][j];
            ans -= sl[t] * f[u][j];
          }
        }
      }
      for (int j = (0); j < (k); j++) {
        sum[u][j] += g[j];
        f[u][j] += sl[j];
      }
    }
  }
  f[u][0]++;
}
void solve() {
  cin >> n >> k;
  for (int i = (1); i < (n); i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, -1);
  cout << ans << '\n';
}
int main() {
  int Test = 1;
  if (multipleTest) {
    cin >> Test;
  }
  for (int i = 0; i < Test; ++i) {
    solve();
  }
}
