#include <bits/stdc++.h>
using namespace std;
long long n, ans, k, cnt1[200010], cnt2[200010][10];
vector<long long> adj[200010];
long long sub(long long a, long long b) { return (a - b + k) % k; }
void dfs(long long st, long long par, long long depth) {
  cnt2[st][depth % k] = 1;
  cnt1[st] = 1;
  for (int l = 0; l < adj[st].size(); l++) {
    long long to = adj[st][l];
    if (to != par) {
      dfs(to, st, depth + 1);
      for (int i = 0; i < k; i++) {
        for (int j = 0; j < k; j++) {
          long long rem = sub(i + j, 2 * depth);
          long long need = sub(k, rem);
          ans += need * cnt2[st][i] * cnt2[to][j];
        }
      }
      for (int i = 0; i < k; i++) {
        cnt2[st][i] += cnt2[to][i];
      }
      cnt1[st] += cnt1[to];
    }
  }
  long long sv = cnt1[st];
  ans += sv * (n - sv);
}
int main() {
  ans = 0;
  memset(cnt1, 0, sizeof(cnt1));
  ;
  memset(cnt2, 0, sizeof(cnt2));
  ;
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(1, -1, 0);
  cout << ans / k << endl;
  return 0;
}
