#include <bits/stdc++.h>
using namespace std;
const int maxi = 1e6;
vector<int> v[maxi];
long long sz[maxi];
long long dp[maxi][7], f[100000], sum[10000];
long long tot, ans, x, y, n, k;
void dfs(int x, int pred) {
  sz[x] = 1;
  for (int i = 0; i < v[x].size(); i++)
    if (v[x][i] != pred) {
      dfs(v[x][i], x);
      tot += sz[v[x][i]] * (n - sz[v[x][i]]);
      sz[x] += sz[v[x][i]];
    }
}
void dfs1(int x, int pred) {
  for (int i = 0; i < v[x].size(); i++)
    if (v[x][i] != pred) {
      dfs1(v[x][i], x);
      for (int j = 0; j < k; j++) dp[x][(j + 1) % k] += dp[v[x][i]][j];
    }
  for (int i = 0; i < k; i++) sum[i] = 0;
  for (int i = 0; i < v[x].size(); i++)
    if (v[x][i] != pred) {
      for (int j = 0; j < k; j++)
        for (int l = 0; l < k; l++)
          sum[(l + j + 2) % k] +=
              dp[v[x][i]][j] * (dp[x][(l + 1) % k] - dp[v[x][i]][l]);
    }
  for (int i = 0; i < k; i++) f[i] += sum[i] / 2;
  for (int j = 0; j < k; j++) f[j] += dp[x][j];
  dp[x][0]++;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1, 0);
  dfs1(1, 0);
  for (int i = 1; i < k; i++) ans += f[i];
  for (long long i = 0; i < k; i++) tot -= i * f[i];
  ans += tot / k;
  printf("%I64d\n", ans);
  return 0;
}
