#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 10;
long long ans = 0;
vector<int> g[MAX];
int dp[MAX][5], s[MAX], n, k;
void dfs(int u, int par = 0, int d = 0) {
  dp[u][d % k] = 1, s[u] = 1;
  for (int v : g[u]) {
    if (v == par) continue;
    dfs(v, u, d + 1);
    for (int i = 0; i < k; i++) {
      for (int j = 0; j < k; j++) {
        int dis = (i + j - 2 * d);
        dis = (dis % k + k) % k;
        int c = (k - dis) % k;
        ans += 1LL * c * dp[u][i] * dp[v][j];
      }
      dp[u][i] += dp[v][i];
    }
    s[u] += s[v];
  }
  ans += 1LL * s[u] * (n - s[u]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1);
  cout << ans / k;
  return 0;
}
