#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 100;
vector<int> v[MAXN];
long long int dp[MAXN][5];
int sz[MAXN];
long long int sum = 0;
int n, k;
void dfs(int node, int p, int d) {
  sz[node] = 1;
  dp[node][d % k] = 1;
  for (int i = 0; i < v[node].size(); i++) {
    int to = v[node][i];
    if (to != p) {
      dfs(to, node, d + 1);
      sz[node] += sz[to];
      for (int a = 0; a < k; a++) {
        for (int b = 0; b < k; b++) {
          int dist = ((a + b - 2 * d) % k + k) % k;
          sum += (abs(k - dist) % k) * dp[node][a] * dp[to][b];
        }
      }
      for (int j = 0; j < k; j++) dp[node][j] += dp[to][j];
    }
  }
  sum += sz[node] * (long long int)(n - sz[node]);
}
int main() {
#pragma warning(disable : 4996)
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(0, -1, 0);
  printf("%lld", sum / k);
  return 0;
}
