#include <bits/stdc++.h>
const int maxn = 2e5 + 10;
using namespace std;
int n, m;
int k, head[maxn];
long long dp[maxn][10], ans, mod, siz[maxn];
struct edge {
  int v, next, w;
} e[maxn << 1];
void adde(int u, int v) {
  e[k].v = v;
  e[k].next = head[u];
  head[u] = k++;
}
void init() {
  k = ans = 0;
  memset(head, -1, sizeof(head));
}
inline void dfs(int u, int fa, int deep) {
  siz[u] = dp[u][deep % mod] = 1;
  for (int i = head[u]; i != -1; i = e[i].next) {
    int v = e[i].v;
    if (v == fa) continue;
    dfs(v, u, deep + 1);
    for (int a = 0; a < mod; a++) {
      for (int b = 0; b < mod; b++) {
        int dis = (((a + b) % mod - (deep * 2) % mod) % mod + mod) % mod;
        int y = (mod - dis) % mod;
        ans += y * dp[u][a] * dp[v][b];
      }
    }
    for (int a = 0; a < mod; a++) dp[u][a] += dp[v][a];
    ans += siz[v] * (n - siz[v]);
    siz[u] += siz[v];
  }
}
int main() {
  init();
  scanf("%d%lld", &n, &mod);
  int u, v;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    adde(u, v);
    adde(v, u);
  }
  dfs(1, 0, 0);
  printf("%lld", ans / mod);
  return 0;
}
