#include <bits/stdc++.h>
const int INF = 1e9;
const long long lINF = 9223372036854775807;
using namespace std;
ifstream in;
ofstream out;
vector<bool> used;
vector<vector<long long>> g;
vector<long long> pl(5);
long long n, k, answ;
vector<long long> dfs(long long v, long long lv) {
  vector<long long> v0(k + 1, 0);
  v0[k] = v0[0] = 1;
  for (auto e : g[v])
    if (e != lv) {
      vector<long long> v1 = dfs(e, v);
      vector<long long> v2(k);
      for (int i = 0; i < (k); i++) {
        for (int j = (0); j < (k); j++) pl[(i + 1 + j) % k] += v1[i] * v0[j];
      }
      for (int i = 0; i < (k); i++) v0[(i + 1) % k] += v1[i];
      v0[k] += v1[k];
      answ += v1[k] * (n - v1[k]);
    }
  return v0;
}
int main() {
  in.open("input.txt");
  out.open("output.txt");
  cin >> n >> k;
  g.resize(n);
  for (int i = 0; i < (n - 1); i++) {
    long long a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0, -1);
  for (int i = 0; i < (5); i++) answ += pl[i] * ((k - i) % k);
  cout << answ / k;
  return 0;
}
