#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> G[200000 + 5];
long long solve;
long long sub_tree[200000 + 5];
long long sub_tree_mod[200000 + 5][6];
void dfs(int node, int parent, int depth) {
  sub_tree[node] = 1;
  sub_tree_mod[node][depth % k] = 1;
  for (int l = 0; l < G[node].size(); l++) {
    int ady = G[node][l];
    if (ady == parent) continue;
    dfs(ady, node, depth + 1);
    for (int i = 0; i < k; i++) {
      for (int j = 0; j < k; j++) {
        int dist = (i + j + k - (2 * depth) % k) % k;
        int miss = k - dist;
        if (miss == k) miss = 0;
        solve += (long long)miss * sub_tree_mod[node][i] * sub_tree_mod[ady][j];
      }
    }
    for (int i = 0; i < k; i++) {
      sub_tree_mod[node][i] += sub_tree_mod[ady][i];
    }
    sub_tree[node] += sub_tree[ady];
  }
  solve += (long long)sub_tree[node] * (n - sub_tree[node]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  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, 0, 0);
  cout << solve / k << '\n';
}
