#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 200;
const int INF = int(1e9) + 7;
const long long LINF = 1ll * INF * INF;
const int md = int(1e9) + 7;
const long double eps = 1e-9;
const long double PI = 3.1415926535897932384626433832795l;
int n, k;
long long dp[MAXN][6], cnt[MAXN][6], sum_dp[6], sum_cnt[6], ans;
vector<vector<int>> g(MAXN);
void dfs(int v, int pr) {
  for (int u : g[v]) {
    if (u != pr) {
      dfs(u, v);
      for (int i = 0; i < k; i++) {
        ans += dp[u][i] + cnt[u][i];
        cnt[v][(i + 1) % k] += cnt[u][i];
        if (i < k - 1) {
          dp[v][i + 1] += dp[u][i];
        } else {
          dp[v][0] += dp[u][k - 1] + cnt[u][k - 1];
        }
      }
    }
  }
  cnt[v][0]++;
  long long add = 0;
  memset(sum_dp, 0, sizeof(sum_dp));
  memset(sum_cnt, 0, sizeof(sum_cnt));
  for (int u : g[v]) {
    if (u == pr) {
      continue;
    }
    for (int j = 0; j < k; j++) {
      sum_dp[j] += dp[u][j];
      sum_cnt[j] += cnt[u][j];
    }
  }
  for (int u : g[v]) {
    if (u == pr) {
      continue;
    }
    for (int i = 0; i < k; i++) {
      for (int j = 0; j < k; j++) {
        long long val_dp = sum_dp[j] - dp[u][j];
        long long val_cnt = sum_cnt[j] - cnt[u][j];
        long long delta = val_cnt * dp[u][i] + val_dp * cnt[u][i] +
                          val_cnt * cnt[u][i] * ((i + j + k + 1) / k);
        if (delta) {
          add += delta;
        }
      }
    }
  }
  assert(add % 2 == 0);
  ans += add / 2;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1, 0);
  cout << ans << endl;
  return 0;
}
