#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const int MAXK = 6;
int n, k;
vector<int> E[MAXN];
long long dp[MAXN][MAXK], sz[MAXN], sol;
void dfs(int x, int p = -1) {
  sz[x] = dp[x][0] = 1;
  for (auto e : E[x]) {
    if (e == p) continue;
    dfs(e, x);
    sz[x] += sz[e];
    for (int i = 0; i < k; ++i)
      for (int j = 0; j < k; ++j) {
        long long left = (k - (i + j + 1) % k) % k;
        sol += left * dp[x][i] * dp[e][j];
      }
    for (int i = 0; i < k; ++i) dp[x][(i + 1) % k] += dp[e][i];
  }
  sol += sz[x] * (n - sz[x]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    E[a].push_back(b);
    E[b].push_back(a);
  }
  dfs(1);
  cout << sol / k;
}
