#include <bits/stdc++.h>
using namespace std;
const int maxm = 200005;
vector<int> v[maxm];
long long dp[maxm][5] = {0}, a[maxm] = {0}, ans = 0;
int k, n;
void dfs(int x, int pre, int num);
int main() {
  int i, j, sum, x, y;
  scanf("%d%d", &n, &k);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1, -1, 0);
  printf("%lld\n", ans / k);
  return 0;
}
void dfs(int x, int pre, int num) {
  dp[x][num % k] = 1;
  a[x] = 1;
  for (int i = 0; i < v[x].size(); i++) {
    int xx = v[x][i];
    if (xx == pre) continue;
    dfs(xx, x, num + 1);
    for (int j = 0; j < k; j++) {
      for (int r = 0; r < k; r++) {
        int dis = (j + r - num * 2) % k;
        int rev = (k - dis + k) % k;
        ans += rev * dp[x][j] * dp[xx][r];
      }
    }
    a[x] += a[xx];
    for (int j = 0; j < k; j++) dp[x][j] += dp[xx][j];
    ans += (n - a[xx]) * a[xx];
  }
}
