#include <bits/stdc++.h>
using namespace std;
vector<int> g[200005];
long long kilk[200005], kilk_k[200005][6];
int n, k;
long long ans;
long long sub(long long a, long long b) { return ((a - b) % k + k) % k; }
void dfs(int u, int p, int d) {
  kilk[u] = 1;
  kilk_k[u][d % k] = 1;
  for (int i = 0; i < g[u].size(); i++) {
    int to = g[u][i];
    if (to == p) continue;
    dfs(to, u, d + 1);
    for (int j = 0; j < k; j++)
      for (int j1 = 0; j1 < k; j1++) {
        long long r = sub(j1 + j, 2 * d);
        long long need = sub(k, r);
        ans += need * kilk_k[u][j1] * kilk_k[to][j];
      }
    for (int j = 0; j < k; j++) kilk_k[u][j] += kilk_k[to][j];
    kilk[u] += kilk[to];
  }
  ans += kilk[u] * (n - kilk[u]);
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1, -1, 0);
  cout << ans / k;
}
