#include <bits/stdc++.h>
using namespace std;
struct NODE {
  int to, next;
} node[400000 + 10];
int n, k, tol;
long long ans;
long long dp[200000 + 10][10], sum[200000 + 10];
int head[200000 + 10];
void addedge(int from, int to) {
  node[tol].to = to;
  node[tol].next = head[from];
  head[from] = tol++;
}
void tree_dp(int now, int fa, int depth) {
  dp[now][depth % k] = sum[now] = 1;
  for (int i = head[now]; i != -1; i = node[i].next) {
    int to = node[i].to;
    if (to != fa) {
      tree_dp(to, now, depth + 1);
      for (int a = 0; a < k; a++) {
        for (int b = 0; b < k; b++) {
          int t = ((a + b) % k - (2 * depth) % k + k) % k;
          t = (k - t + k) % k;
          ans += t * dp[now][a] * dp[to][b];
        }
      }
      for (int a = 0; a < k; a++) dp[now][a] += dp[to][a];
      sum[now] += sum[to];
      ans += sum[to] * (n - sum[to]);
    }
  }
}
int main() {
  while (scanf("%d %d", &n, &k) != EOF) {
    memset(head, -1, sizeof(head));
    tol = 0;
    ans = 0ll;
    for (int i = 1; i <= n - 1; i++) {
      int from, to;
      scanf("%d %d", &from, &to);
      addedge(from, to);
      addedge(to, from);
    }
    memset(dp, 0, sizeof(dp));
    memset(sum, 0, sizeof(sum));
    tree_dp(1, 0, 0);
    printf("%lld\n", ans / k);
  }
  return 0;
}
