#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
vector<int> G[maxn];
int totson[maxn], subtree[maxn][10], n, k, u, v;
long long ans;
int subtract(int a, int b) { return ((a - b) % k + k) % k; }
void dfs(int cur, int par, int dept) {
  totson[cur] = subtree[cur][dept % k] = 1;
  for (int i = 0; i < G[cur].size(); i++) {
    int son = G[cur][i];
    if (son == par) continue;
    dfs(son, cur, dept + 1);
    for (int a = 0; a < k; a++) {
      for (int b = 0; b < k; b++) {
        int dis = subtract(a + b, 2 * dept);
        int needs = subtract(k, dis);
        ans += (long long)needs * subtree[cur][a] * subtree[son][b];
      }
    }
    totson[cur] += totson[son];
    for (int j = 0; j < k; j++) subtree[cur][j] += subtree[son][j];
  }
  ans += (long long)totson[cur] * (n - totson[cur]);
}
int main() {
  ans = 0;
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, -1, 0);
  ans /= k;
  cout << ans << endl;
}
