#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
vector<long long> adj[2001025];
long long dp[2001025][7], K, sub[2001025], n;
void dfs(int u, int par) {
  sub[u] = 1;
  dp[u][0] = 1;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v != par) {
      dfs(v, u);
      for (int j = 0; j < K; j++) {
        for (int p = 0; p < K; p++) {
          long long need = (K - (p + j + 1) % K) % K;
          ans += need * dp[u][j] * dp[v][p];
        }
      }
      for (int j = 0; j < K; j++) dp[u][(j + 1) % K] += dp[v][j];
      sub[u] += sub[v];
    }
  }
  ans += (sub[u]) * (n - sub[u]);
}
int main() {
  long long x, y;
  cin >> n >> K;
  for (int i = 0; i < n - 1; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, -1);
  cout << (ans / K) << endl;
}
