#include <bits/stdc++.h>
using namespace std;
const int max_n = 202222, max_k = 8, inf = 1011111111;
int n, k;
long long ans, dp[max_n][max_k], sum[max_n][max_k];
vector<int> g[max_n];
void write(int v) {
  cout << "$" << v << "  ";
  for (int i = 0; i < k; ++i) {
    cout << dp[v][i] << " ";
  }
  cout << "   ";
  for (int i = 0; i < k; ++i) {
    cout << sum[v][i] << " ";
  }
  cout << endl;
}
void dfs(int v, int p) {
  dp[v][0] = 1;
  sum[v][0] = 0;
  for (int i = 0; i < g[v].size(); ++i) {
    if (g[v][i] == p) {
      continue;
    }
    dfs(g[v][i], v);
    for (int j = 0; j < k; ++j) {
      for (int q = 0; q < k; ++q) {
        long long pl = 0;
        ans += dp[v][j] * (sum[g[v][i]][q] + (q == 0) * dp[g[v][i]][q]) +
               dp[g[v][i]][q] * sum[v][j];
        if (j != 0 && q + 1 != k && j + q + 1 <= k) {
          pl = -dp[v][j] * dp[g[v][i]][q];
        }
        ans += pl;
      }
    }
    for (int j = 0; j < k; ++j) {
      dp[v][(j + 1) % k] += dp[g[v][i]][j];
      sum[v][(j + 1) % k] += sum[g[v][i]][j] + (j == 0) * dp[g[v][i]][j];
    }
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, -1);
  printf("%I64d\n", ans);
  return 0;
}
