#include <bits/stdc++.h>
using namespace std;
void splitstr(const string &s, vector<string> &v) {
  istringstream in(s);
  copy(istream_iterator<string>(in), istream_iterator<string>(),
       back_inserter(v));
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
  cerr << *it << " = " << a << '\n';
  err(++it, args...);
}
struct point {
  int x, y;
  double len() { return sqrt(x * x + y * y); }
  double angel() { return atan2(y, x); }
  point operator+(const point &o) { return {x + o.x, y + o.y}; }
  point operator*(const int d) { return {x * d, y * d}; }
  int operator*(const point &o) { return x * o.x + y * o.y; }
  int operator^(const point &o) { return x * o.y - y * o.x; }
};
const int maxn = (2e5) + 100;
const long long INF = (1e9) + 7;
const long double EPS = 1e-8;
vector<int> e[maxn];
long long ans = 0;
int n, k;
vector<pair<long long, long long> > qqlex(
    vector<pair<long long, long long> > up) {
  vector<pair<long long, long long> > backup;
  for (int i = 0; i < (int)k; i++) {
    backup.push_back({0, 0});
  }
  if (k == 1) {
    backup[0].first = up[0].first + up[0].second;
    backup[0].second = up[0].second;
  } else {
    backup[1].first = up[0].first + up[0].second;
    backup[1].second = up[0].second;
    for (int i = 1; i <= (int)k - 2; i++) {
      backup[i + 1] = up[i];
    }
    backup[0] = up[k - 1];
  }
  return backup;
}
vector<pair<long long, long long> > dfs(
    int v, int p, vector<pair<long long, long long> > up) {
  vector<pair<long long, long long> > backup = qqlex(up);
  backup[1 % k].first++;
  backup[1 % k].second++;
  vector<pair<long long, long long> > down;
  for (int i = 0; i < (int)k; i++) down.push_back({0, 0});
  for (int i = 0; i < (int)up.size(); i++) {
    ans += up[i].first;
  }
  for (int i = 0; i < (int)e[v].size(); i++) {
    if (e[v][i] != p) {
      vector<pair<long long, long long> > nd = dfs(e[v][i], v, backup);
      for (int j = 0; j < (int)k; j++) {
        down[j].first += nd[j].first;
        down[j].second += nd[j].second;
      }
      vector<pair<long long, long long> > ggg = qqlex(nd);
      for (int j = 0; j < (int)k; j++) {
        backup[j].first += ggg[j].first;
        backup[j].second += ggg[j].second;
      }
    }
  }
  vector<pair<long long, long long> > nwd = qqlex(down);
  nwd[1 % k].first++;
  nwd[1 % k].second++;
  return nwd;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < (int)n - 1; i++) {
    int x, y;
    cin >> x >> y;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  vector<pair<long long, long long> > up;
  for (int i = 0; i < (int)k; i++) up.push_back({0, 0});
  dfs(1, -1, up);
  cout << ans;
  return 0;
}
