#include <bits/stdc++.h>
using namespace std;
const int N = 200001;
int n, k, child[N], pathLen[N][5];
long long sum;
vector<int> adjL[N];
void DFS(int node, int per) {
  for (int ch : adjL[node])
    if (ch != per) {
      DFS(ch, node);
      child[node] += child[ch] + 1;
      sum += 1ll * (n - child[ch] - 1) * (child[ch] + 1);
      for (int i = (0); i <= (int)(k - 1); ++i)
        for (int j = (0); j <= (int)(k - 1); ++j)
          sum += 1ll * (k - (i + j + 1) % k) % k * pathLen[node][i] *
                 pathLen[ch][j];
      for (int i = (0); i <= (int)(k - 1); ++i)
        pathLen[node][(i + 1) % k] += pathLen[ch][i];
    }
  ++pathLen[node][0];
  for (int i = (1); i <= (int)(k - 1); ++i)
    sum += 1ll * (k - i) * pathLen[node][i];
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = (2); i <= (int)(n); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    adjL[a].push_back(b), adjL[b].push_back(a);
  }
  DFS(1, -1);
  printf("%lld\n", sum / k);
  return 0;
}
