#include <bits/stdc++.h>
using namespace std;
long long dp[200010][7], tot, n, k, dp2[200010][7];
vector<int> edge[200010];
void dfs(int cn, int p) {
  dp2[cn][0] = 1;
  for (int i = 0; i < edge[cn].size(); i++) {
    int to = edge[cn][i];
    if (to == p) continue;
    dfs(to, cn);
    for (int i = 0; i < k; i++) {
      for (int j = 0; j < k; j++) {
        long long pp = dp[cn][i] * dp2[to][j] + dp[to][j] * dp2[cn][i];
        if (!i && !j)
          pp += dp2[cn][i] * dp2[to][j];
        else if (pp && i > 0 && j > 0 && (i + j + 1 <= k))
          pp -= dp2[cn][i] * dp2[to][j];
        tot += pp;
      }
    }
    for (int i = 0; i < k; i++) {
      dp[cn][(i + 1) % k] += dp[to][i];
      if (!i) dp[cn][(i + 1) % k] += dp2[to][i];
    }
    for (int i = 0; i < k; i++) dp2[cn][(i + 1) % k] += dp2[to][i];
  }
}
int main() {
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  dfs(1, -1);
  cout << tot << endl;
}
