#include<cstdio>
const int maxn=200005;
int k;
typedef long long ll;
struct edge{
  int to,next;
}lst[maxn<<1];int len=1,first[maxn];
void addedge(int a,int b){
  lst[len].to=b;lst[len].next=first[a];first[a]=len++;
}
bool vis[maxn];
int tot,sz[maxn],f[maxn],root;
void get_root(int x,int p){
  sz[x]=1;f[x]=0;
  for(int pt=first[x];pt;pt=lst[pt].next){
    if(lst[pt].to==p||vis[lst[pt].to])continue;
    get_root(lst[pt].to,x);
    sz[x]+=sz[lst[pt].to];
    if(sz[lst[pt].to]>f[x])f[x]=sz[lst[pt].to];
  }
  if(tot-sz[x]>f[x])f[x]=tot-sz[x];
  if(root==0||f[x]<f[root])root=x;
}
int g[maxn];
ll sum[5];int num[5];
ll ans=0;
int q[maxn],dis[maxn];int dfn[maxn],clk;
void calc(int x){//printf("calc%d\n",x);
  int head=0,tail=0;q[tail++]=x;dis[x]=1;dfn[x]=++clk;
  while(head!=tail){
    int x=q[head++];
    for(int pt=first[x];pt;pt=lst[pt].next){
      if(vis[lst[pt].to]||dfn[lst[pt].to]==clk)continue;
      dfn[lst[pt].to]=clk;dis[lst[pt].to]=dis[x]+1;q[tail++]=lst[pt].to;
    }
  }//sz[x]=tail;
  for(int i=0;i<tail;++i){
    int x=q[i];
    for(int j=0;j<k;++j){
      ans+=dis[x]/k*1ll*num[j];//printf("%d\n",dis[x]);
      ans+=sum[j];//printf("n%d\n",num[j]);
      if(j+dis[x]%k>=k)ans+=num[j];
    }
  }
  for(int i=0;i<tail;++i){
    int x=q[i];
    num[(dis[x]+k-1)%k]++;sum[(dis[x]+k-1)%k]+=(dis[x]+k-1)/k;
  }
  //  sz[x]=tail;
}
int depth=0;
void dfs(int x){
  //  printf("x=%d\n",x);
  //printf("%d\n",depth);
  ++depth;
  for(int i=0;i<k;++i)sum[i]=0,num[i]=0;
  num[k-1]=1;
  vis[x]=true;
  for(int pt=first[x];pt;pt=lst[pt].next){
    if(vis[lst[pt].to])continue;
    calc(lst[pt].to);
  }
  for(int pt=first[x];pt;pt=lst[pt].next){
    if(vis[lst[pt].to])continue;
    root=0;tot=sz[lst[pt].to];get_root(lst[pt].to,0);

    dfs(root);
  }
  //  --depth;
}
int main(){
  //  freopen("1.in","r",stdin);
  int n;scanf("%d%d",&n,&k);
  for(int i=1,a,b;i<n;++i){
    scanf("%d%d",&a,&b);addedge(a,b);addedge(b,a);
  }
  tot=n;get_root(1,0);dfs(root);
  printf("%lld\n",ans);
  return 0;
}


#include<cstdio>
const int maxn=200005;
int k;
typedef long long ll;
struct edge{
  int to,next;
}lst[maxn<<1];int len=1,first[maxn];
void addedge(int a,int b){
  lst[len].to=b;lst[len].next=first[a];first[a]=len++;
}
bool vis[maxn];
int tot,sz[maxn],f[maxn],root;
void get_root(int x,int p){
  sz[x]=1;f[x]=0;
  for(int pt=first[x];pt;pt=lst[pt].next){
    if(lst[pt].to==p||vis[lst[pt].to])continue;
    get_root(lst[pt].to,x);
    sz[x]+=sz[lst[pt].to];
    if(sz[lst[pt].to]>f[x])f[x]=lst[pt].to;
  }
  if(tot-sz[x]>f[x])f[x]=tot-sz[x];
  if(root==0||f[x]<f[root])root=x;
}
int g[maxn];
ll sum[5];int num[5];
ll ans=0;
int q[maxn],dis[maxn];int dfn[maxn],clk;
void calc(int x){//printf("calc%d\n",x);
  int head=0,tail=0;q[tail++]=x;dis[x]=1;dfn[x]=++clk;
  while(head!=tail){
    int x=q[head++];
    for(int pt=first[x];pt;pt=lst[pt].next){
      if(vis[lst[pt].to]||dfn[lst[pt].to]==clk)continue;
      dfn[lst[pt].to]=clk;dis[lst[pt].to]=dis[x]+1;q[tail++]=lst[pt].to;
    }
  }
  for(int i=0;i<tail;++i){
    int x=q[i];
    for(int j=0;j<k;++j){
      ans+=dis[x]/k*1ll*num[j];//printf("%d\n",dis[x]);
      ans+=sum[j];//printf("n%d\n",num[j]);
      if(j+dis[x]%k>=k)ans+=num[j];
    }
  }
  for(int i=0;i<tail;++i){
    int x=q[i];
    num[(dis[x]+k-1)%k]++;sum[(dis[x]+k-1)%k]+=(dis[x]+k-1)/k;
  }
}
void dfs(int x){//printf("dfs%d\n",x);
  for(int i=0;i<k;++i)sum[i]=0,num[i]=0;
  num[k-1]=1;
  vis[x]=true;
  for(int pt=first[x];pt;pt=lst[pt].next){
    if(vis[lst[pt].to])continue;
    calc(lst[pt].to);
  }
  for(int pt=first[x];pt;pt=lst[pt].next){
    if(vis[lst[pt].to])continue;
    root=0;tot=sz[lst[pt].to];get_root(lst[pt].to,0);
    dfs(root);
  }
}
int main(){
  int n;scanf("%d%d",&n,&k);
  for(int i=1,a,b;i<n;++i){
    scanf("%d%d",&a,&b);addedge(a,b);addedge(b,a);
  }
  tot=n;get_root(1,0);dfs(root);
  printf("%lld\n",ans);
  return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <array>

using namespace std;

const int N = 200000;
const int K = 5;

int k;
vector<int> g[N];

using DP = array<pair<int, long long>, K>;
DP dp[N];
long long ans = 0;

template<int mult>
void add(DP& dst, const DP& src) {
  for (int i = 0; i < k - 1; ++i) {
    dst[i + 1].first += mult * src[i].first;
    dst[i + 1].second += mult * src[i].second;
  }
  dst[0].first += mult * src[k - 1].first;
  dst[0].second += mult * src[k - 1].second;
  dst[1 % k].second += mult * src[0].first;
}

void dfs1(int u, int p) {
  dp[u][0] = {1, 0};
  for (int v : g[u]) {
    if (v != p) {
      dfs1(v, u);
      add<+1>(dp[u], dp[v]);
    }
  }
}

void dfs2(int u, int p) {
  if (p != -1) {
    DP parent_without_us = dp[p];
    add<-1>(parent_without_us, dp[u]);
    add<+1>(dp[u], parent_without_us);
  }
  for (int i = 0; i < k; ++i) {
    ans += dp[u][i].second;
  }
  for (int v : g[u]) {
    if (v != p) {
      dfs2(v, u);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  cin >> n >> k;
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  dfs1(0, -1);
  dfs2(0, -1);

  cout << ans / 2 << endl;

  return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <array>

using namespace std;

const int N = 200000;
const int K = 5;

int k;
vector<int> g[N];

using DP = array<pair<int, long long>, K>;
DP dp[N];
long long ans = 0;

void add(DP& dst, const DP& src, int mult) {
  for (int i = 0; i < k; ++i) {
    dst[(i + 1) % k].first += mult * src[i].first;
    dst[(i + 1) % k].second += mult * src[i].second;
    if (i == 0) {
       dst[(i + 1) % k].second += mult * src[i].first;
    }
  }
}

void dfs1(int u, int p) {
  dp[u][0] = {1, 0};
  for (int v : g[u]) {
    if (v != p) {
      dfs1(v, u);
      add(dp[u], dp[v], +1);
    }
  }
}

void dfs2(int u, int p) {
  if (p != -1) {
    DP parent_without_us = dp[p];
    add(parent_without_us, dp[u], -1);
    add(dp[u], parent_without_us, +1);
  }
  for (int i = 0; i < k; ++i) {
    ans += dp[u][i].second;
  }
  for (int v : g[u]) {
    if (v != p) {
      dfs2(v, u);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  cin >> n >> k;
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  dfs1(0, -1);
  dfs2(0, -1);

  cout << ans / 2 << endl;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 200010;
const ll maxk = 6;

ll n,k;
ll dp[maxn][maxk];
ll pd[maxn][maxk];
vector<ll>G[maxn];
ll sum;

void Read()
{
    ll u,v;
    scanf("%lld %lld",&n,&k);
    for(ll i=1;i<n;i++)
    {
        scanf("%lld %lld",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
}

void dfs(ll u,ll f)
{
    ll sb=0;
    for(ll i=0;i<(ll)G[u].size();i++)
    {
        ll v=G[u][i];
        if(v==f) continue;
        dfs(v,u);
        for(ll j=0;j<k;j++)
            dp[u][(j+1)%k]+=dp[v][j],sum+=dp[v][j],sb+=dp[v][j];
        dp[u][5]+=dp[v][0]-1;
        dp[u][5]+=dp[v][5];
        sum+=dp[u][5];
        sb+=dp[u][5];
    }
    //printf("---%lld:%lld\n",u,sb);
    dp[u][0]++;
}

void dfs2(ll u,ll f)
{
    for(ll i=0;i<(ll)G[u].size();i++)
    {
        ll v=G[u][i];
        if(v==f) continue;
        ll sb=0;
        for(ll i=0;i<k;i++) pd[v][(i+1)%k]+=pd[u][i];
        for(ll i=0;i<k;i++) pd[v][(i+1)%k]+=dp[u][i];
        for(ll i=0;i<k;i++) pd[v][(i+2)%k]-=dp[v][i];
        for(ll i=0;i<k;i++) sum+=pd[v][i],sb+=pd[v][i];
        pd[v][5]+=pd[v][1]-1;
        pd[v][5]+=pd[u][5]+dp[u][5]-dp[v][0]+1-dp[v][5];
        sum+=pd[v][5],sb+=pd[v][5];
        //printf("---%lld:%lld\n",v,sb);
        dfs2(v,u);
    }
}

void solve()
{
    dfs(1,-1);
    dfs2(1,-1);
    printf("%lld\n",sum/2);
}

int main()
{
    Read();
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 200010;
const ll maxk = 6;

ll n,k;
ll dp[maxn][maxk];
ll pd[maxn][maxk];
vector<ll>G[maxn];
ll sum;

void Read()
{
    ll u,v;
    scanf("%lld %lld",&n,&k);
    for(ll i=1;i<n;i++)
    {
        scanf("%lld %lld",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
}

void dfs(ll u,ll f)
{
    ll sb=0;
    for(ll i=0;i<(ll)G[u].size();i++)
    {
        ll v=G[u][i];
        if(v==f) continue;
        dfs(v,u);
        for(ll j=0;j<k;j++)
            dp[u][(j+1)%k]+=dp[v][j],sum+=dp[v][j],sb+=dp[v][j];
        dp[u][5]+=dp[v][0]-1;
        dp[u][5]+=dp[v][5];
        sum+=dp[u][5];
        sb+=dp[u][5];
    }
    //printf("---%lld:%lld\n",u,sb);
    dp[u][0]++;
}

void dfs2(ll u,ll f)
{
    for(ll i=0;i<(ll)G[u].size();i++)
    {
        ll v=G[u][i];
        if(v==f) continue;
        ll sb=0;
        for(ll i=0;i<k;i++) pd[v][(i+1)%k]+=pd[u][i];
        for(ll i=0;i<k;i++) pd[v][(i+1)%k]+=dp[u][i];
        for(ll i=0;i<k;i++) pd[v][(i+2)%k]-=dp[v][i];
        for(ll i=0;i<k;i++) sum+=pd[v][i],sb+=pd[v][i];
        pd[v][5]+=pd[v][min(1ll,k-1)]-1;
        pd[v][5]+=pd[u][5]+dp[u][5]-dp[v][0]+1-dp[v][5];
        sum+=pd[v][5],sb+=pd[v][5];
        //printf("---%lld:%lld\n",v,sb);
        dfs2(v,u);
    }
}

void solve()
{
    dfs(1,-1);
    dfs2(1,-1);
    printf("%lld\n",sum/2);
}

int main()
{
    Read();
    solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int int64_t

int n, k;
const int maxn = 2e5 + 42, maxk = 10;
vector<int> g[maxn];
int sz[maxn][maxk];
int up[maxn][maxk];
int ans = 0;
int penalty = 0;
void dfs1(int v = 0, int p = 0)
{
	sz[v][0] = 1;
	for(auto u: g[v])
	{
		if(u == p)
			continue;
		dfs1(u, v);
		for(int z = 0; z < k; z++)
			sz[v][(z + 1) % k] += sz[u][z];
	}
}

void dfs2(int v = 0, int p = 0)
{
	for(auto u: g[v])
	{
		if(u == p)
			continue;
		for(int z = 0; z < k; z++)
			up[u][(z + 1) % k] = up[v][z] + sz[v][z] - sz[u][(z + k - 1) % k];
		dfs2(u, v);
	}
	if(v != p)
	{
		int sm = accumulate(sz[v], sz[v] + k, 0);
		int smu = accumulate(up[v], up[v] + k, 0);
		ans += smu * sz[v][0] + sm * up[v][1 % k];
	}
}

signed main()
{
	//freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	for(int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs1();
	dfs2();
	//assert(ans % 2 == 0);
	cout << ans / 2 << endl;
}
//89035321450


#include <bits/stdc++.h>

using namespace std;

#define int int64_t

int n, k;
const int maxn = 2e5 + 42, maxk = 10;
vector<int> g[maxn];
int sz[maxn][maxk];
int up[maxn][maxk];
int ans = 0;
int penalty = 0;
void dfs1(int v = 0, int p = 0)
{
	sz[v][0] = 1;
	for(auto u: g[v])
	{
		if(u == p)
			continue;
		dfs1(u, v);
		for(int z = 0; z < k; z++)
			sz[v][(z + 1) % k] += sz[u][z];
	}
}

void dfs2(int v = 0, int p = 0)
{
	for(auto u: g[v])
	{
		if(u == p)
			continue;
		for(int z = 0; z < k; z++)
			up[u][(z + 1) % k] = up[v][z] + sz[v][z] - sz[u][(z + k - 1) % k];
		dfs2(u, v);
	}
	if(v != p)
	{
		int sm = accumulate(sz[v], sz[v] + k, 0);
		int smu = accumulate(up[v], up[v] + k, 0);
		ans += smu * sz[v][0] + sm * up[v][1];
	}
}

signed main()
{
	//freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	for(int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs1();
	dfs2();
	cout << ans / 2 << endl;
}
//89035321450


#include <bits/stdc++.h>

using namespace std;

#define int int64_t

int n, k;
const int maxn = 2e5 + 42, maxk = 10;
vector<int> g[maxn];
int sz[maxn][maxk];
int up[maxn][maxk];
int ans = 0;
int penalty = 0;
void dfs1(int v = 0, int p = 0)
{
	sz[v][0] = 1;
	for(auto u: g[v])
	{
		if(u == p)
			continue;
		dfs1(u, v);
		for(int z = 0; z < k; z++)
			sz[v][(z + 1) % k] += sz[u][z];
	}
}

void dfs2(int v = 0, int p = 0)
{
	for(auto u: g[v])
	{
		if(u == p)
			continue;
		for(int z = 0; z < k; z++)
			up[u][(z + 1) % k] = up[v][z] + sz[v][z] - sz[u][(z + k - 1) % k];
		dfs2(u, v);
	}
	if(v != p)
	{
		int sm = accumulate(sz[v], sz[v] + k, 0);
		int smu = accumulate(up[v], up[v] + k, 0);
		ans += smu * sz[v][0] + sm * up[v][1];
	}
}

signed main()
{
	freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	for(int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs1();
	dfs2();
	cout << ans / 2 << endl;
}
//89035321450


#include <iostream>
#include <iomanip>
#include <cstdint>
#include <vector>

using namespace std;
using Graph = vector< vector< int32_t > >;

class Solver {
public:
    Solver(Graph& graph, int32_t vert_count, int32_t jump_len) :
        G(graph), n(vert_count), k(jump_len),
        count_subtree(vector< vector < int32_t > >(n, vector < int32_t >(jump_len))),
        total_subtree(vector < int32_t >(n))
    { }

    long long Solve();

protected:
    int32_t n, k;
    Graph G;
    long long answer{ 0 };

    vector< vector < int32_t > > count_subtree;
    vector < int32_t > total_subtree;

    int32_t Subtract(int32_t, int32_t);
    void Dfs(int32_t, int32_t, char);
};

int32_t Solver::Subtract(int32_t a, int32_t b) {
    return ((a - b)%k + k)%k;
}

void Solver::Dfs(int32_t from, int32_t parent, char depth) {
    count_subtree[from][depth%k] = total_subtree[from] = 1;

    for (auto to : G[from]) {
        if (to == parent) continue;

        Dfs(to, from, depth+1);

        for (auto i = 0; i < k; ++i) {
            for (auto j = 0; j < k; ++j) {
                int32_t rem = Subtract(i+j, 2*depth);
                int32_t needs = Subtract(k, rem);

                answer += (long long)needs*count_subtree[from][i]*count_subtree[to][j];
            }
        }

        for (auto i = 0; i < k; ++i) {
            count_subtree[from][i] += count_subtree[to][i];
        }

        total_subtree[from] += total_subtree[to];
    }

    answer += total_subtree[from]*(n - total_subtree[from]);
}

long long Solver::Solve() {
    Dfs(0, -1, 0);
    return answer/k;
}

int main (int argc, char* argv[]) {
    int32_t n, k;
    cin >> n >> k;

    Graph G(n, vector< int32_t >());
    for (int i = 1; i < n; ++i) {
        int32_t u, v;
        cin >> u >> v;
        u--; v--;

        G[u].push_back(v);
        G[v].push_back(u);
    }

    Solver solver(G, n, k);
    cout << solver.Solve() << endl;

    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdint>
#include <vector>

using namespace std;
using Graph = vector< vector< int32_t > >;

class Solver {
public:
    Solver(Graph& graph, int32_t vert_count, int32_t jump_len) :
        G(graph), n(vert_count), k(jump_len),
        count_subtree(vector< vector < int32_t > >(n, vector < int32_t >(jump_len))),
        total_subtree(vector < int32_t >(n))
    { }

    long long Solve();

protected:
    int32_t n, k;
    Graph G;
    long long answer{ 0 };

    vector< vector < int32_t > > count_subtree;
    vector < int32_t > total_subtree;

    int32_t Subtract(int32_t, int32_t);
    void Dfs(int32_t, int32_t, int32_t);
};

int32_t Solver::Subtract(int32_t a, int32_t b) {
    return ((a - b)%k + k)%k;
}

void Solver::Dfs(int32_t from, int32_t parent, int32_t depth) {
    count_subtree[from][depth%k] = total_subtree[from] = 1;

    for (auto to : G[from]) {
        if (to == parent) continue;

        Dfs(to, from, depth+1);

        for (auto i = 0; i < k; ++i) {
            for (auto j = 0; j < k; ++j) {
                int32_t rem = Subtract(i+j, 2*depth);
                int32_t needs = Subtract(k, rem);

                answer += (long long)needs*count_subtree[from][i]*count_subtree[to][j];
            }
        }

        for (auto i = 0; i < k; ++i) {
            count_subtree[from][i] += count_subtree[to][i];
        }

        total_subtree[from] += total_subtree[to];
    }

    answer += total_subtree[from]*(n - total_subtree[from]);
}

long long Solver::Solve() {
    Dfs(0, -1, 0);
    return answer/k;
}

int main (int argc, char* argv[]) {
    int32_t n, k;
    cin >> n >> k;

    Graph G(n, vector< int32_t >());
    for (int i = 1; i < n; ++i) {
        int32_t u, v;
        cin >> u >> v;
        u--; v--;

        G[u].push_back(v);
        G[v].push_back(u);
    }

    Solver solver(G, n, k);
    cout << solver.Solve() << endl;

    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdint>
#include <vector>

using namespace std;
using Graph = vector< vector< int32_t > >;

class Solver {
public:
    Solver(Graph& graph, int32_t vert_count, int32_t jump_len) :
        G(graph), n(vert_count), k(jump_len),
        count_subtree(vector< vector < int32_t > >(n, vector < int32_t >(jump_len))),
        total_subtree(vector < int32_t >(n))
    { }

    long long Solve();

protected:
    int32_t n, k;
    Graph G;
    long long answer{ 0 };

    vector< vector < int32_t > > count_subtree;
    vector < int32_t > total_subtree;

    int32_t Subtract(int32_t, int32_t);
    void Dfs(int32_t, int32_t, int32_t);
};

int32_t Solver::Subtract(int32_t a, int32_t b) {
    return ((a - b)%k + k)%k;
}

void Solver::Dfs(int32_t from, int32_t parent, int32_t depth) {
    count_subtree[from][depth%k] = total_subtree[from] = 1;

    for (auto to : G[from]) {
        if (to == parent) continue;

        Dfs(to, from, depth+1);

        for (auto i = 0; i < k; ++i) {
            for (auto j = 0; j < k; ++j) {
                int32_t rem = Subtract(i+j, 2*depth);
                int32_t needs = Subtract(k, rem);

                answer += (long long)needs*count_subtree[from][i]*count_subtree[to][j];
            }
        }

        for (auto i = 0; i < k; ++i) {
            count_subtree[from][i] += count_subtree[to][i];
        }

        total_subtree[from] += total_subtree[to];
    }

    answer += (long long)total_subtree[from]*(n - total_subtree[from]);
}

long long Solver::Solve() {
    Dfs(0, -1, 0);
    return answer/k;
}

int main (int argc, char* argv[]) {
    int32_t n, k;
    cin >> n >> k;

    Graph G(n, vector< int32_t >());
    for (int i = 1; i < n; ++i) {
        int32_t u, v;
        cin >> u >> v;
        u--; v--;

        G[u].push_back(v);
        G[v].push_back(u);
    }

    Solver solver(G, n, k);
    cout << solver.Solve() << endl;

    return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define Error(x) cout << #x << " = " << x << endl

using namespace std;
typedef long long ll;
const int mod = 1000000007;

int n, k;
ll L;
vector<vector<int>> g;
vector<ll> total;
vector<int> visited;
vector<vector<ll>> cnt;

int dfs(int cur) {
    visited[cur] = 1;
    ll r = 1;
    for(int n: g[cur]) {
        if(visited[n] == 0) {
            r += dfs(n);
            ++cnt[n][0];
            for(int i = 0; i < k; ++i) {
                for(int j = 0; j < k; ++j) {
                    total[(i + j + 1) % k] += cnt[cur][i] * cnt[n][j];
                }
            }
            --cnt[n][0];
            for(int i = 0; i < k; ++i) {
                cnt[cur][(i + 1) % k] += cnt[n][i];
            }
            ++cnt[cur][1 % k];
        }
    }
    for(int i = 0; i < k; ++i)  total[i] += cnt[cur][i];
    L += r * (n - r);
    return r;
}

int main()
{   _
    //ifstream cin("test.txt");
    cin >> n >> k;
    g.resize(n + 1);
    total.resize(k, 0);
    visited.resize(n + 1, 0);
    cnt = vector<vector<ll>>(n + 1, vector<ll>(k, 0));
    for(int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    L = 0;
    dfs(1);

    for(int i = 1; i < k; ++i)  L += total[i] * (k - i);
    cout << L / k << endl;

    return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define Error(x) cout << #x << " = " << x << endl

using namespace std;
typedef long long ll;
const int mod = 1000000007;

int n, k;
ll L;
vector<vector<int>> g;
vector<ll> total;
vector<int> visited;
vector<vector<ll>> cnt;

int dfs(int cur) {
    visited[cur] = 1;
    int r = 1;
    for(int n: g[cur]) {
        if(visited[n] == 0) {
            r += dfs(n);
            ++cnt[n][0];
            for(int i = 0; i < k; ++i) {
                for(int j = 0; j < k; ++j) {
                    total[(i + j + 1) % k] += cnt[cur][i] * cnt[n][j];
                }
            }
            --cnt[n][0];
            for(int i = 0; i < k; ++i) {
                cnt[cur][(i + 1) % k] += cnt[n][i];
            }
            ++cnt[cur][1 % k];
        }
    }
    for(int i = 0; i < k; ++i)  total[i] += cnt[cur][i];
    L += r * (n - r);
    return r;
}

int main()
{   _
    //ifstream cin("test.txt");
    cin >> n >> k;
    g.resize(n + 1);
    total.resize(k, 0);
    visited.resize(n + 1, 0);
    cnt = vector<vector<ll>>(n + 1, vector<ll>(k, 0));
    for(int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    L = 0;
    dfs(1);

    for(int i = 1; i < k; ++i)  L += total[i] * (k - i);
    cout << L / k << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define K 1005
#define lp(i,n) for(int i=0;i<n;i++)
#define MP make_pair
#define N (200*K)
#define MOD 1000000007
#define F first
#define S second
#define FASTIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

void read() {
    freopen("in", "r", stdin);
}
typedef long long ll;
typedef pair<int, int> pi;
ll L[N][10], cnt[N][10];
vector<int> v[N];
int n, k;
ll ans = 0;

int dfs(int i, int p = -1) {
    for (int z = 0; z < k; z++)cnt[i][z] = L[i][z] = 0;
    ll tmp = 0;
    cnt[i][0] += 1;
    for (int j = 0; j < v[i].size(); j++) {
        int child = v[i][j];
        if (child == p)continue;
        dfs(child, i);
        for (int j = 0; j < k; j++) {
            for (int jj = 0; jj < k; jj++) {
                tmp += L[i][j] * cnt[child][jj] + L[child][jj] * cnt[i][j] ;
                 tmp+=cnt[child][jj] * cnt[i][j]*((j+jj+k)/k);

            }
        }
        for (int j = 0; j < k; j++) {
            cnt[i][j] += cnt[child][(j - 1 + k) % k];
        }
        for (int j = 0; j < k; j++) {
            L[i][j] += L[child][(j - 1 + k) % k];
            if (j == 0)L[i][j] += cnt[child][(j - 1 + k) % k];
        }
    }
    ans += tmp;
}

int main() {
    cin >> n>>k;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(1);
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define K 1005
#define lp(i,n) for(int i=0;i<n;i++)
#define MP make_pair
#define N (2000*K)
#define MOD 1000000007
#define F first
#define S second
#define FASTIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

void read() {
    freopen("in", "r", stdin);
}
typedef long long ll;
typedef pair<int, int> pi;
ll L[N][10], cnt[N][10];
vector<int> v[N];
int n, k;
ll ans = 0;

int dfs(int i, int p = -1) {
    for (int z = 0; z < k; z++)cnt[i][z] = L[i][z] = 0;
    ll tmp = 0;
    cnt[i][0] += 1;
    for (int j = 0; j < v[i].size(); j++) {
        int child = v[i][j];
        if (child == p)continue;
        dfs(child, i);
        for (int j = 0; j < k; j++) {
            for (int jj = 0; jj < k; jj++) {
                tmp += L[i][j] * cnt[child][jj] + L[child][jj] * cnt[i][j] ;
                 tmp+=cnt[child][jj] * cnt[i][j]*((j+jj+k)/k);

            }
        }
        for (int j = 0; j < k; j++) {
            cnt[i][j] += cnt[child][(j - 1 + k) % k];
        }
        for (int j = 0; j < k; j++) {
            L[i][j] += L[child][(j - 1 + k) % k];
            if (j == 0)L[i][j] += cnt[child][(j - 1 + k) % k];
        }
    }
    ans += tmp;
}

int main() {
    cin >> n>>k;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(1);
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define nl '\n'
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 200005, maxk = 10;

int N,K;
ll dp[maxn][maxk],cnt[maxn][maxk],res;
vector<int> g[maxn];

void solve(int u, int p){
    cnt[u][0] = 1;
    for(int v:g[u]){
        if(v == p) continue;
        solve(v,u);
        for(int i=0; i<K; i++){
            int nm = (i+1)%K;
            for(int t=0; t<K; t++){
                ll ts = (dp[v][i]+cnt[v][i])*cnt[u][t];
                ts+=dp[u][t]*cnt[v][i];
                if((nm+t)%K == 0) res+=ts/K;
                else{
                    int d = (nm+t)%K;
                    ll add = 1ll*cnt[v][i]*cnt[u][t]*(K-d);
                    res+=(ts+add)/K;
                }
            }
        }
        for(int i=0; i<K; i++){
            int nm = (i+1)%K;
            cnt[u][nm]+=cnt[v][i];
            dp[u][nm]+=dp[v][i]+cnt[v][i];
        }
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> K;
    for(int i=1; i<N; i++){
        int a,b; cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }
    solve(1,-1);
    cout << res << nl;
}


#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define nl '\n'
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 200005, maxk = 10;

int N,K,cnt[maxn][maxk];
ll dp[maxn][maxk],res;
vector<int> g[maxn];

void solve(int u, int p){
    cnt[u][0] = 1;
    for(int v:g[u]){
        if(v == p) continue;
        solve(v,u);
        for(int i=0; i<K; i++){
            int nm = (i+1)%K;
            for(int t=0; t<K; t++){
                ll ts = (dp[v][i]+cnt[v][i])*cnt[u][t];
                ts+=dp[u][t]*cnt[v][i];
                if((nm+t)%K == 0) res+=ts/K;
                else{
                    int d = (nm+t)%K;
                    ll add = 1ll*cnt[v][i]*cnt[u][t]*(K-d);
                    res+=(ts+add)/K;
                }
            }
        }
        for(int i=0; i<K; i++){
            int nm = (i+1)%K;
            cnt[u][nm]+=cnt[v][i];
            dp[u][nm]+=dp[v][i]+cnt[v][i];
        }
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> K;
    for(int i=1; i<N; i++){
        int a,b; cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }
    solve(1,-1);
    cout << res << nl;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define N 500005
#define ll long long
#define p(t) cout<<t;
#define f(i,n) for(i=0;i<n;i++)
#define g(i,n) for(i=1;i<=n;i++)
#define s(x) scanf("%I64d",&x);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#include <string>

ll r,m,a[N],n,b[N],c[N];
vector<ll> v[N];

struct rd{
    ll e[5]={0};
};
vector<rd> remainds[N];

rd dfs(ll x,ll dis){
    ll i,j,k;
    a[x]=1;
    rd temp,fi;
    for(i=0;i<v[x].size();i++){
        if(a[v[x][i]]==1)continue;
        temp = dfs(v[x][i],dis+1);
        remainds[x].pb(temp);
        for(j=0;j<r;j++)
            fi.e[(j+1)%r]+=temp.e[j];
    }
     fi.e[1ll%r]++;
    m=m+dis/r+(dis%r!=0);
    return fi;
}

void dfg(ll x, rd pre, ll ans){
    ll i,j,k,l;
    rd tot;
    b[x]=1;
    f(i,r)tot.e[(i+1)%r]=pre.e[i];
    ans=ans+tot.e[1];
    rd n1,te,pt;
    for(i=0;i<remainds[x].size();i++){
        f(j,r)te.e[j]+=remainds[x][i].e[j];
    }
    ans-=te.e[0];
    tot.e[1]++;
    f(j,r)tot.e[j]+=te.e[j];
    l=0;
    m=m+ans;
    for(i=0;i<v[x].size();i++){
        if(b[v[x][i]]==1)continue;
        rd ft;
        f(j,r)ft.e[j]=tot.e[j]-remainds[x][l].e[j];
        l++;
        dfg(v[x][i],ft,ans);
    }

}

ll dft(ll x){
    ll i,j,k=1;
    c[x]=1;
    rd temp,fi;
    for(i=0;i<v[x].size();i++){
        if(c[v[x][i]]==1)continue;
        k+=dft(v[x][i]);
    }
    m=m+k*(n-k);
    //cout<<x<<" "<<k<<" "<<n-k<<" \n";
    return k;
}

int main()
{
ios_base::sync_with_stdio(0);
ll k=0,t=0,x,sum=0,q,y=0,l=0,i,j,z,p;
cin>>n>>r;
f(i,n-1){
    cin>>x>>y;
    v[x].pb(y); v[y].pb(x);
}
a[1]=1;
rd n1,gurz,temp;
for(i=0;i<v[1].size();i++){
        n1 = dfs(v[1][i],1);
        remainds[1].pb(n1);
        for(j=0;j<r;j++)gurz.e[j]+=n1.e[j];
}
x=m;
b[1]=1;
for(i=0;i<v[1].size();i++){
        n1=remainds[1][i];
        for(j=0;j<r;j++)temp.e[j]=gurz.e[j]-n1.e[j];
       dfg(v[1][i],temp,x);
}
if(r>1)
cout<<m/2;
else {
        m=0;
        c[1]=1;
        dft(1);
        cout<<m;
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define N 500005
#define ll long long
#define p(t) cout<<t;
#define f(i,n) for(i=0;i<n;i++)
#define g(i,n) for(i=1;i<=n;i++)
#define s(x) scanf("%I64d",&x);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#include <string>

ll r,m,a[N],n,b[N],c[N];
vector<ll> v[N];

struct rd{
    ll e[5]={0};
};
vector<rd> remainds[N];

rd dfs(ll x,ll dis){
    ll i,j,k;
    a[x]=1;
    rd temp,fi;
    for(i=0;i<v[x].size();i++){
        if(a[v[x][i]]==1)continue;
        temp = dfs(v[x][i],dis+1);
        remainds[x].pb(temp);
        for(j=0;j<r;j++)
            fi.e[(j+1)%r]+=temp.e[j];
    }
     fi.e[1ll%r]++;
    m=m+dis/r+(dis%r!=0);
    return fi;
}

void dfg(ll x, rd pre, ll ans){
    ll i,j,k,l;
    rd tot;
    b[x]=1;
    f(i,r)tot.e[(i+1)%r]=pre.e[i];
    ans=ans+tot.e[1];
    rd n1,te,pt;
    for(i=0;i<remainds[x].size();i++){
        f(j,r)te.e[j]+=remainds[x][i].e[j];
    }
    ans-=te.e[0];
    tot.e[1]++;
    f(j,r)tot.e[j]+=te.e[j];
    l=0;
    m=m+ans;
    for(i=0;i<v[x].size();i++){
        if(b[v[x][i]]==1)continue;
        rd ft;
        f(j,r)ft.e[j]=tot.e[j]-remainds[x][l].e[j];
        l++;
        dfg(v[x][i],ft,ans);
    }

}

int main()
{
ios_base::sync_with_stdio(0);
ll k=0,t=0,x,sum=0,q,y=0,l=0,i,j,z,p;
cin>>n>>r;
f(i,n-1){
    cin>>x>>y;
    v[x].pb(y); v[y].pb(x);
}
a[1]=1;
rd n1,gurz,temp;
for(i=0;i<v[1].size();i++){
        n1 = dfs(v[1][i],1);
        remainds[1].pb(n1);
        for(j=0;j<r;j++)gurz.e[j]+=n1.e[j];
}
x=m;
b[1]=1;
for(i=0;i<v[1].size();i++){
        n1=remainds[1][i];
        for(j=0;j<r;j++)temp.e[j]=gurz.e[j]-n1.e[j];
       dfg(v[1][i],temp,x);
}
cout<<m/2;
return 0;
}


#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS 1e-10
#define set0(x) memset((x),0,sizeof(x))
#define setINF(x) memset((x),63,sizeof(x))
/*
	Problem: Bear and Tree Jumps
	Source: Codeforces 771C
	Author: fts2001 (the_silliest)
 */
using namespace std;
int n,k,sz[200005],dp[200005][8];
long long ans;
vector<int> g[200005];
void dfs(int x,int p,int d){
    dp[x][d%k]=sz[x]=1;
    for(int it=0;it<g[x].size();it++){
        int u=g[x][it];
        if(p==u)continue;
        dfs(u,x,d+1);
        for(int i=0;i<k;i++){
            for(int j=0;j<k;j++){
                ans+=1ll*(((2*d-(i+j))%k+k)%k)*dp[x][i]*dp[u][j];
            }
        }
        sz[x]+=sz[u];
        for(int i=0;i<k;i++){
            dp[x][i]+=dp[u][i];
        }
    }
    ans+=1ll*sz[x]*(n-sz[x]);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        u--;
        v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(0,-1,0);
    cout<<ans/k<<endl;
    return 0;
}


#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS 1e-10
#define set0(x) memset((x),0,sizeof(x))
#define setINF(x) memset((x),63,sizeof(x))
/*
	Problem: Bear and Tree Jumps
	Source: Codeforces 771C
	Author: fts2001 (the_silliest)
 */
using namespace std;
int n,k,sz[200005],dp[200005][8];
long long ans;
vector<int> g[200005];
void dfs(int x,int p,int d){
    dp[x][d%k]=sz[x]=1;
    for(int it=0;it<g[x].size();it++){
        int u=g[x][it];
        if(p==u)continue;
        dfs(u,x,d+1);
        for(int i=0;i<k;i++){
            for(int j=0;j<k;j++){
                ans+=1ll*((2*d-(i+j)+k)%k)*dp[x][i]*dp[u][j];
            }
        }
        sz[x]+=sz[u];
        for(int i=0;i<k;i++){
            dp[x][i]+=dp[u][i];
        }
    }
    ans+=1ll*sz[x]*(n-sz[x]);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        u--;
        v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(0,-1,0);
    cout<<ans/k<<endl;
    return 0;
}


#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS 1e-10
#define set0(x) memset((x),0,sizeof(x))
#define setINF(x) memset((x),63,sizeof(x))
/*
	Problem: Bear and Tree Jumps
	Source: Codeforces 771C
	Author: fts2001 (the_silliest)
 */
using namespace std;
int n,k,sz[200005],dp[200005][8];
long long ans;
vector<int> g[200005];
void dfs(int x,int p,int d){
    dp[x][d%k]=sz[x]=1;
    for(int it=0;it<g[x].size();it++){
        int u=g[x][it];
        if(p==u)continue;
        dfs(u,x,d+1);
        for(int i=0;i<k;i++){
            for(int j=0;j<k;j++){
                ans+=1ll*((2*d-(i+j)+k*k)%k)*dp[x][i]*dp[u][j];
            }
        }
        sz[x]+=sz[u];
        for(int i=0;i<k;i++){
            dp[x][i]+=dp[u][i];
        }
    }
    ans+=1ll*sz[x]*(n-sz[x]);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        u--;
        v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(0,-1,0);
    cout<<ans/k<<endl;
    return 0;
}


  //File Name: cf771C.cpp
  //Created Time: 2017年03月19日 星期日 17时47分05秒

#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int MAXN = 200000 + 5;
vector<int> tree[MAXN];
int siz[MAXN],g[MAXN][5];
int k;
void dfs1(int u,int pa){
	siz[u] = 1;
	g[u][0] = 1;
	for(auto v:tree[u]){
		if(v == pa) continue;
		dfs1(v,u);
		siz[u] += siz[v];
		for(int j=0;j<k;++j)
			g[u][(j + 1) % k] += g[v][j];
	}
}
void dfs2(int u,int pa){
	for(auto v:tree[u]){
		if(v == pa) continue;
		int tmp[5] = {0};
		for(int i=0;i<k;++i)
			tmp[(i+1)%k] = g[u][i] - g[v][(i-1+k)%k];
		for(int i=0;i<k;++i)
			g[v][i] += tmp[i];
		dfs2(v,u);
	}
}
LL solve(int n){
	dfs1(1,1);
	dfs2(1,1);
//	for(int i=1;i<=n;++i)
//		for(int j=0;j<k;++j)
//			printf("i = %d j = %d g = %d\n",i,j,g[i][j]);
	int s[5] = {0};
	for(int i=1;i<=n;++i)
		for(int j=0;j<k;++j)
			s[j] += g[i][j];
	for(int i=1;i<k;++i)
		s[i] /= 2;
	LL dis = 0,sum = 0;
	for(int i=1;i<=n;++i)
		dis += 1LL * siz[i] * (n - siz[i]);
	for(int i=1;i<k;++i){
		dis -= 1LL * i * s[i];
		sum += s[i];
	}
	dis = dis / k + sum;
	return dis;
}
int main(){
	int n;
	scanf("%d %d",&n,&k);
	for(int i=1,u,v;i<n;++i){
		scanf("%d %d",&u,&v);
		tree[u].push_back(v);
		tree[v].push_back(u);
	}
	printf("%lld\n",solve(n));
	return 0;
}


  //File Name: cf771C.cpp
  //Created Time: 2017年03月19日 星期日 17时47分05秒

#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int MAXN = 200000 + 5;
vector<int> tree[MAXN];
int siz[MAXN],g[MAXN][5];
int k;
void dfs1(int u,int pa){
	siz[u] = 1;
	g[u][0] = 1;
	for(auto v:tree[u]){
		if(v == pa) continue;
		dfs1(v,u);
		siz[u] += siz[v];
		for(int j=0;j<k;++j)
			g[u][(j + 1) % k] += g[v][j];
	}
}
void dfs2(int u,int pa){
	for(auto v:tree[u]){
		if(v == pa) continue;
		int tmp[5] = {0};
		for(int i=0;i<k;++i)
			tmp[(i+1)%k] = g[u][i] - g[v][(i-1+k)%k];
		for(int i=0;i<k;++i)
			g[v][i] += tmp[i];
		dfs2(v,u);
	}
}
LL solve(int n){
	dfs1(1,1);
	dfs2(1,1);
//	for(int i=1;i<=n;++i)
//		for(int j=0;j<k;++j)
//			printf("i = %d j = %d g = %d\n",i,j,g[i][j]);
	LL s[5] = {0};
	for(int i=1;i<=n;++i)
		for(int j=0;j<k;++j)
			s[j] += g[i][j];
	for(int i=1;i<k;++i)
		s[i] /= 2;
	LL dis = 0,sum = 0;
	for(int i=1;i<=n;++i)
		dis += 1LL * siz[i] * (n - siz[i]);
	for(int i=1;i<k;++i){
		dis -= 1LL * i * s[i];
		sum += s[i];
	}
	dis = dis / k + sum;
	return dis;
}
int main(){
	int n;
	scanf("%d %d",&n,&k);
	for(int i=1,u,v;i<n;++i){
		scanf("%d %d",&u,&v);
		tree[u].push_back(v);
		tree[v].push_back(u);
	}
	printf("%lld\n",solve(n));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long LL;

const int maxn = 200009;
int g[maxn][9], n, K, a, b;
vector<int> e[maxn];
LL f[maxn][9], ans;

void merge(int u, int v, int dep) {
	int tmp = 0;
	for (int l=0; l<=K-1; l++)
		for (int r=0; r<=K-1; r++) {
			tmp = (l + r - 2*dep%K + K) % K;
			ans += ((f[u][l] - 1LL * dep * g[u][l]) * g[v][r] + (f[v][r] - 1LL * (dep+tmp) * g[v][r]) * g[u][l]) / K;
			if (tmp) ans += g[u][l] * g[v][r];
		}
	for (int i=0; i<=K-1; i++) {
		f[u][i] += f[v][i];
		g[u][i] += g[v][i];
	}
}

void dfs(int u, int fa, int dep) {
	g[u][dep%K]++; f[u][dep%K] += dep;
	for (auto v : e[u])
		if (v != fa) {
			dfs(v, u, dep + 1);
			merge(u, v, dep);
		}
}

int main() {
	scanf("%d%d", &n, &K);
	for (int i=1; i<=n-1; i++) {
		scanf("%d%d", &a, &b);
		e[a].push_back(b);
		e[b].push_back(a);
	}
	dfs(1, 0, 0);
	printf("%I64u\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long double LL;

const int maxn = 200009;
int g[maxn][9], n, K, a, b;
vector<int> e[maxn];
LL f[maxn][9], ans;

void merge(int u, int v, int dep) {
	int tmp = 0;
	for (int l=0; l<=K-1; l++)
		for (int r=0; r<=K-1; r++) {
			tmp = (l + r - 2*dep%K + K) % K;
			ans += ((f[u][l] - 1.0 * dep * g[u][l]) * g[v][r]
				  + (f[v][r] - 1.0 * (dep+tmp) * g[v][r]) * g[u][l]) / K;
			if (tmp) ans += g[u][l] * g[v][r];
		}
	for (int i=0; i<=K-1; i++) {
		f[u][i] += f[v][i];
		g[u][i] += g[v][i];
	}
}

void dfs(int u, int fa, int dep) {
	g[u][dep%K]++; f[u][dep%K] += dep;
	for (auto v : e[u])
		if (v != fa) {
			dfs(v, u, dep + 1);
			merge(u, v, dep);
		}
}

int main() {
	scanf("%d%d", &n, &K);
	for (int i=1; i<=n-1; i++) {
		scanf("%d%d", &a, &b);
		e[a].push_back(b);
		e[b].push_back(a);
	}
	dfs(1, 0, 0);
	printf("%.0Lf\n", ans);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
#define ll long long
using namespace std;
const int maxm = 200005;
vector<int>v[maxm];
ll dp[maxm][5] = { 0 }, a[maxm] = { 0 }, ans = 0;
int k, n;
void dfs(int x, int pre, int num);
int main()
{
    int  i, j, sum, x, y;
    scanf("%d%d", &n, &k);
    for (i = 1;i < n;i++)
    {
        scanf("%d%d", &x, &y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1, -1, 0);
    printf("%lld\n", ans / k);
    return 0;
}
void dfs(int x, int pre, int num)
{
    dp[x][num%k] = 1;
    a[x] = 1;
    for (int i = 0;i < v[x].size();i++)
    {
        int xx = v[x][i];
        if (xx == pre)
            continue;
        dfs(xx, x, num + 1);
        for (int j = 0;j < k;j++)
        {
            for (int r = 0;r < k;r++)
            {
                int dis = (j + r - num * 2) % k;
                int rev = (k - dis) % k;
                ans += rev*dp[x][j] * dp[xx][r];
            }
        }
        a[x] += a[xx];
        for (int j = 0;j < k;j++)
            dp[x][j] += dp[xx][j];
        ans += (n - a[xx])*a[xx];
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long LL;

const int maxn = 200009;
int g[maxn][9], n, K, a, b;
vector<int> e[maxn];
LL f[maxn][9], ans;

void merge(int u, int v, int dep) {
	int tmp = 0;
	for (int l=0; l<=K-1; l++)
		for (int r=0; r<=K-1; r++) {
			tmp = (l + r - 2*dep%K + K) % K;
			ans += ((f[u][l] - 1LL * dep * g[u][l]) * g[v][r] + (f[v][r] - 1LL * (dep+tmp) * g[v][r]) * g[u][l]) / K;
			if (tmp) ans += g[u][l] * g[v][r];
		}
	for (int i=0; i<=K-1; i++) {
		f[u][i] += f[v][i];
		g[u][i] += g[v][i];
	}
}

void dfs(int u, int fa, int dep) {
	g[u][dep%K]++; f[u][dep%K] += dep;
	for (auto v : e[u])
		if (v != fa) {
			dfs(v, u, dep + 1);
			merge(u, v, dep);
		}
}

int main() {
	scanf("%d%d", &n, &K);
	for (int i=1; i<=n-1; i++) {
		scanf("%d%d", &a, &b);
		e[a].push_back(b);
		e[b].push_back(a);
	}
	dfs(1, 0, 0);
	printf("%I64u\n", ans / K);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long double LL;

const int maxn = 200009;
int g[maxn][9], n, K, a, b;
vector<int> e[maxn];
LL f[maxn][9], ans;

void merge(int u, int v, int dep) {
	int tmp = 0;
	for (int l=0; l<=K-1; l++)
		for (int r=0; r<=K-1; r++) {
			tmp = (l + r - 2*dep%K + K) % K;
			ans += ((f[u][l] - 1.0 * dep * g[u][l]) * g[v][r] + (f[v][r] - 1LL * (dep+tmp) * g[v][r]) * g[u][l]) / K;
			if (tmp) ans += g[u][l] * g[v][r];
		}
	for (int i=0; i<=K-1; i++) {
		f[u][i] += f[v][i];
		g[u][i] += g[v][i];
	}
}

void dfs(int u, int fa, int dep) {
	g[u][dep%K]++; f[u][dep%K] += dep;
	for (auto v : e[u])
		if (v != fa) {
			dfs(v, u, dep + 1);
			merge(u, v, dep);
		}
}

int main() {
	scanf("%d%d", &n, &K);
	for (int i=1; i<=n-1; i++) {
		scanf("%d%d", &a, &b);
		e[a].push_back(b);
		e[b].push_back(a);
	}
	dfs(1, 0, 0);
	printf("%.0Lf\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

const int maxn = 200009;
int g[maxn][9], n, K, a, b;
vector<int> e[maxn];
LL f[maxn][9], ans;

void merge(int u, int v, int dep) {
	int tmp = 0;
	for (int l=0; l<=K-1; l++)
		for (int r=0; r<=K-1; r++) {
			tmp = (l + r - 2*dep%K + K) % K;
			//printf("%d %d %d %d %d\n", u, v, l, r, tmp);
			ans += (f[u][l] - 1LL * dep * g[u][l]) * g[v][r];
			ans += (f[v][r] - 1LL * (dep+tmp) * g[v][r]) * g[u][l];
			if (tmp) ans += g[u][l] * g[v][r] * K;
		}
	for (int i=0; i<=K-1; i++) {
		f[u][i] += f[v][i];
		g[u][i] += g[v][i];
	}
}

void dfs(int u, int fa, int dep) {
	g[u][dep%K]++; f[u][dep%K] += dep;
	for (auto v : e[u])
		if (v != fa) {
			dfs(v, u, dep + 1);
			merge(u, v, dep);
		}
}

int main() {
	scanf("%d%d", &n, &K);
	for (int i=1; i<=n-1; i++) {
		scanf("%d%d", &a, &b);
		e[a].push_back(b);
		e[b].push_back(a);
	}
	dfs(1, 0, 0);
	printf("%I64d\n", ans / K);
	return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define pb push_back

#define left(x) ((x) << 1)
#define right(x) ((x) << 1 | 1)
#define mid(x, y) ((x) + (y) >> 1)

#define INF (1 << 30)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;

const int maxk = 5;
const int maxn = 2 * 1e5 + 17;

int N, K;
int subtree[maxk][maxn], whole[maxk][maxn];

ll ans[maxn];

vector<int> graph[maxn];

void DFS(int u, int p)
{
    subtree[0][u] = 1;

    for (int v : graph[u])
        if (v != p) {
            DFS(v, u);
            ans[u] += ans[v];

            for (int i = 0; i < K; i++)
                for (int j = 0; j < K; j++) {
                    ans[u] += 1LL * whole[i][u] * subtree[j][v] + 1LL * subtree[i][u] * whole[j][v];
                    ans[u] += 1LL * ((i + j + K) / K) * subtree[i][u] * subtree[j][v];
                }

            for (int i = 0; i < K; i++) {
                subtree[(i + 1) % K][u] += subtree[i][v],
                whole[(i +1) % K][u] += whole[i][v];
                if (i + 1 >= K) whole[(i + 1) % K][u] += subtree[i][v];
            }
        }
}

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> N >> K;
    for (int i = 1; i < N; i++) {
        int x, y; cin >> x >> y;
        graph[x].pb(y); graph[y].pb(x);
    }

    DFS(1, 1);
    cout << ans[1] << endl;
    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define pb push_back

#define left(x) ((x) << 1)
#define right(x) ((x) << 1 | 1)
#define mid(x, y) ((x) + (y) >> 1)

#define INF (1 << 30)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;

const int maxk = 5;
const int maxn = 2 * 1e5 + 17;

int N, K;

ll ans[maxn];
ll subtree[maxk][maxn], whole[maxk][maxn];

vector<int> graph[maxn];

void DFS(int u, int p)
{
    subtree[0][u] = 1;

    for (int v : graph[u])
        if (v != p) {
            DFS(v, u);
            ans[u] += ans[v];

            for (int i = 0; i < K; i++)
                for (int j = 0; j < K; j++) {
                    ans[u] += 1LL * whole[i][u] * subtree[j][v] + 1LL * subtree[i][u] * whole[j][v];
                    ans[u] += 1LL * ((i + j + K) / K) * subtree[i][u] * subtree[j][v];
                }

            for (int i = 0; i < K; i++) {
                subtree[(i + 1) % K][u] += subtree[i][v],
                whole[(i +1) % K][u] += whole[i][v];
                if (i + 1 >= K) whole[(i + 1) % K][u] += subtree[i][v];
            }
        }
}

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> N >> K;
    for (int i = 1; i < N; i++) {
        int x, y; cin >> x >> y;
        graph[x].pb(y); graph[y].pb(x);
    }

    DFS(1, 1);
    cout << ans[1] << endl;
    return 0;
}


#include<bits/stdc++.h>
#define ind(a) scanf("%d", &a)
#define inlld(a) scanf("%lld", &a)
#define pb push_back
#define f first
#define s second
#define ind2(a, b) scanf("%d%d", &a, &b)
#define ind3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define inlld2(a, b) scanf("%lld%lld", &a, &b)
#define inlld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)

using namespace std;

const int N=1e5+5;
const int MOD=1e9+7;
typedef long long ll;
typedef long double ld;

int power(int a,int b,int m = MOD){
	if(b == 0) return 1;
	if(b == 1) return a;
	int x = power(a,b/2,m)%m;
	x = (x*x)%m;
	if(b%2) return (x*a)%m;
	return x;
}
ll n, k, ans, stsiz[N], kdist[N][10];
vector<ll>adj[N];
void dfs(ll u, ll par, ll depth)
{
	stsiz[u]=1;
	kdist[u][depth%k]=1;
	for(ll a=0; a<adj[u].size(); a++)
	{
		ll v=adj[u][a];
		if(v!=par)
		{
			dfs(v, u, depth+1);
			for(ll b=0; b<k; b++)
				for(ll c=0; c<k; c++)
				{
					ll rem=(b+c-2*depth+k)%k;
					ans+=((k-rem)%k)*kdist[u][b]*kdist[v][c];
				}
			for(ll b=0; b<k; b++)
				kdist[u][b]+=kdist[v][b];
			stsiz[u]+=stsiz[v];
		}
	}
	ans+=stsiz[u]*(n-stsiz[u]);
}
int main()
{
	inlld2(n, k);
	for(ll a=1; a<n; a++)
	{
		ll u, v;
		inlld2(u, v);
		adj[u].pb(v);
		adj[v].pb(u);
	}
	dfs(1, 0, 0);
	// dfs2(1, 0);
	printf("%lld\n", ans/k);
	return 0;
}


#include<bits/stdc++.h>
#define ind(a) scanf("%d", &a)
#define inlld(a) scanf("%lld", &a)
#define pb push_back
#define f first
#define s second
#define ind2(a, b) scanf("%d%d", &a, &b)
#define ind3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define inlld2(a, b) scanf("%lld%lld", &a, &b)
#define inlld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)

using namespace std;

const int N=2e5+5;
const int MOD=1e9+7;
typedef long long ll;
typedef long double ld;

int power(int a,int b,int m = MOD){
	if(b == 0) return 1;
	if(b == 1) return a;
	int x = power(a,b/2,m)%m;
	x = (x*x)%m;
	if(b%2) return (x*a)%m;
	return x;
}
ll n, k, ans, stsiz[N], kdist[N][10];
vector<ll>adj[N];
void dfs(ll u, ll par, ll depth)
{
	stsiz[u]=1;
	kdist[u][depth%k]=1;
	for(ll a=0; a<adj[u].size(); a++)
	{
		ll v=adj[u][a];
		if(v!=par)
		{
			dfs(v, u, depth+1);
			for(ll b=0; b<k; b++)
				for(ll c=0; c<k; c++)
				{
					ll rem=(b+c-2*depth+k)%k;
					ans+=((k-rem)%k)*kdist[u][b]*kdist[v][c];
				}
			for(ll b=0; b<k; b++)
				kdist[u][b]+=kdist[v][b];
			stsiz[u]+=stsiz[v];
		}
	}
	ans+=stsiz[u]*(n-stsiz[u]);
}
int main()
{
	inlld2(n, k);
	for(ll a=1; a<n; a++)
	{
		ll u, v;
		inlld2(u, v);
		adj[u].pb(v);
		adj[v].pb(u);
	}
	dfs(1, 0, 0);
	// dfs2(1, 0);
	printf("%lld\n", ans/k);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, k;
long long ans;

vector<int> a[200100];
long long dp[200100];
int sz[200100][5];
int fsz[200100];

void dfs(int v, int p)
{
	sz[v][0] = 1;
	for (int i: a[v])
		if (i != p)
		{
			dfs(i, v);
			for (int j = 0; j < k; j++)
				sz[v][(j+1)%k] += sz[i][j];
			dp[v] += dp[i] + sz[i][0];
		}
	for (int i = 0; i < k; i++)
		fsz[v] += sz[v][i];

	ans += dp[v];
	for (int i: a[v])
		if (i != p)
		{
			dp[v] -= (dp[i] + sz[i][0]);
			int x[5];
			for (int j = 0; j < k; j++)
				x[j] = sz[v][j] - sz[i][(k+j-1)%k];
			ans += fsz[i] * dp[v] + dp[i] * (fsz[v] - fsz[i]);
			for (int j1 = 0; j1 < k; j1++)
				for (int j2 = 0; j2 < k; j2++)
					if (!j1 && !j2)
						ans += sz[i][j1] * x[j2];
					else if ((k-j1)%k + (k-j2)%k >= k + 1)
						ans -= sz[i][j1] * x[j2];
			dp[v] += (dp[i] + sz[i][0]);
		}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> k;
	for (int i = 1; i < n; i++)
	{
		int x, y;
		cin >> x >> y;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	dfs(1, -1);

	cout << ans / 2 << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, k;
long long ans;

vector<int> a[200100];
long long dp[200100];
int sz[200100][5];
int fsz[200100];

void dfs(int v, int p)
{
	sz[v][0] = 1;
	for (int i: a[v])
		if (i != p)
		{
			dfs(i, v);
			for (int j = 0; j < k; j++)
				sz[v][(j+1)%k] += sz[i][j];
			dp[v] += dp[i] + sz[i][0];
		}
	for (int i = 0; i < k; i++)
		fsz[v] += sz[v][i];

	ans += dp[v];
	for (int i: a[v])
		if (i != p)
		{
			dp[v] -= (dp[i] + sz[i][0]);
			int x[5];
			for (int j = 0; j < k; j++)
				x[j] = sz[v][j] - sz[i][(k+j-1)%k];
			ans += fsz[i] * dp[v] + dp[i] * (fsz[v] - fsz[i]);
			for (int j1 = 0; j1 < k; j1++)
				for (int j2 = 0; j2 < k; j2++)
					if (!j1 && !j2)
						ans += (long long)sz[i][j1] * x[j2];
					else if ((k-j1)%k + (k-j2)%k >= k + 1)
						ans -= (long long)sz[i][j1] * x[j2];
			dp[v] += (dp[i] + sz[i][0]);
		}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> k;
	for (int i = 1; i < n; i++)
	{
		int x, y;
		cin >> x >> y;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	dfs(1, -1);

	cout << ans / 2 << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <set>
#include <iterator>
#include <stack>

using namespace std;

#define ff first
#define ss second
#define N 200005
#define pb push_back
#define mp make_pair
#define ll long long
#define MOD 1000000007
#define INF 1000000000
#define MAX 2e18

ll distUp[N][5], distDown[N][5], ans;
int cntUp[N][5], cntDown[N][5], n, k;
vector<int> graph[N];

void dfs0(int v, int p){
    cntDown[v][0] = 1;

    for(int i=0 ; i<graph[v].size() ; i++){
        int u = graph[v][i];
        if(u == p)
            continue;
        dfs0(u, v);

        for(int mod=0 ; mod<k ; mod++){
            int prev = (mod - 1 + k) % k;
            cntDown[v][mod] = cntDown[v][mod] + cntDown[u][prev];
            distDown[v][mod] = distDown[v][mod] + distDown[u][prev] + cntDown[u][prev];
        }
    }
}

void dfs1(int v, int p){
    for(int i=0 ; i<graph[v].size() ; i++){
        int u = graph[v][i];
        if(u == p)
            continue;

        for(int mod=0 ; mod<k ; mod++){
            int prev = (mod - 1 + k) % k;
            int last = (mod - 2 + k) % k;
            cntUp[u][mod] = cntUp[v][prev] + cntDown[v][prev] - cntDown[u][last];
            // distUp[u][mod] = distUp[v][prev] + cntUp[u][prev] + cntDown[u][prev] + distDown[v][prev] - distDown[u][mod] - 2 * cntDown[u][mod];
            distUp[u][mod] = distUp[v][prev] + cntUp[v][prev] + distDown[v][prev] + cntDown[v][prev] - distDown[u][last] - 2 * cntDown[u][last];
        }

        dfs1(u, v);
    }

    ans += distDown[v][0] / k + distUp[v][0] / k;
    for(int i=1 ; i<k ; i++){
        ans += (distDown[v][i] - i * cntDown[v][i]) / k + cntDown[v][i] + (distUp[v][i] - i * cntUp[v][i]) / k + cntUp[v][i];
    }
}

int main(){
	ios_base::sync_with_stdio(false);
    cin>>n>>k;

    for(int i=0 ; i<n-1 ; i++){
        int u, v;
        cin>>u>>v;

        graph[u].pb(v), graph[v].pb(u);
    }

    dfs0(1, 1);
    dfs1(1, 1);

    // for(int i=1 ; i<=n ; i++){
    //     cout<<"node "<<i<<" : \n";
    //     for(int j=0 ; j<k ; j++){
    //         cout<<j<<" -> "<<cntDown[i][j]<<" "<<distDown[i][j]<<", "<<cntUp[i][j]<<" "<<distUp[i][j]<<endl;
    //     }
    //     cout<<endl;
    // }

    cout<<ans / 2<<"\n";

	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <set>
#include <iterator>
#include <stack>

using namespace std;

#define ff first
#define ss second
#define N 200005
#define pb push_back
#define mp make_pair
#define ll long long
#define MOD 1000000007
#define INF 1000000000
#define MAX 2e18

ll distUp[N][5], distDown[N][5], ans;
int cntUp[N][5], cntDown[N][5], n, k;
vector<int> graph[N];

void dfs0(int v, int p){
    cntDown[v][0] = 1;

    for(int i=0 ; i<graph[v].size() ; i++){
        int u = graph[v][i];
        if(u == p)
            continue;
        dfs0(u, v);

        for(int mod=0 ; mod<k ; mod++){
            int prev = (mod - 1 + k) % k;
            cntDown[v][mod] = cntDown[v][mod] + cntDown[u][prev];
            distDown[v][mod] = distDown[v][mod] + distDown[u][prev] + cntDown[u][prev];
        }
    }
}

void dfs1(int v, int p){
    for(int i=0 ; i<graph[v].size() ; i++){
        int u = graph[v][i];
        if(u == p)
            continue;

        for(int mod=0 ; mod<k ; mod++){
            int prev = (mod - 1 + k) % k;
            int last = (mod - 2 + k) % k;
            cntUp[u][mod] = cntUp[v][prev] + cntDown[v][prev] - cntDown[u][last];
            distUp[u][mod] = distUp[v][prev] + cntUp[v][prev] + distDown[v][prev] + cntDown[v][prev] - distDown[u][last] - 2 * cntDown[u][last];
        }

        dfs1(u, v);
    }

    ans += distDown[v][0] / k + distUp[v][0] / k;
    for(int i=1 ; i<k ; i++){
        ans += (distDown[v][i] - i * cntDown[v][i]) / k + cntDown[v][i] + (distUp[v][i] - i * cntUp[v][i]) / k + cntUp[v][i];
    }
}

int main(){
	ios_base::sync_with_stdio(false);
    cin>>n>>k;

    for(int i=0 ; i<n-1 ; i++){
        int u, v;
        cin>>u>>v;

        graph[u].pb(v), graph[v].pb(u);
    }

    dfs0(1, 1);
    dfs1(1, 1);

    cout<<ans / 2<<"\n";

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> g[200005];
int cs[200005][6];
int sz[200005];
long long ans;
int n,k;

int to_add(int x,int y)
{
    int val = ((x-y)%k+k)%k;
    if(val==0) return 0;
    return k-val;
}

void dfs(int u,int p,int d)
{
    sz[u]=1;
    cs[u][d%k]=1;
    for(int x: g[u])
    {
        if(x!=p)
        {
            dfs(x,u,d+1);
            sz[u]+=sz[x];
            for(int i=0;i<k;i++) for(int j=0;j<k;j++)
                ans+= to_add(i+j,2*d)*cs[u][i]*cs[x][j];
            for(int i=0;i<k;i++) cs[u][i]+=cs[x][i];
        }
    }
    ans+=sz[u]*(n-sz[u]);
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int x,y; cin>>n>>k;
    for(int i=1;i<n;i++)
    {
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1,0,0);
    cout<<ans/k;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> g[200005];
int cs[200005][6];
int sz[200005];
long long ans;
int n,k;

int to_add(int x,int y)
{
    int val = ((x-y)%k+k)%k;
    if(val==0) return 0;
    return k-val;
}

void dfs(int u,int p,int d)
{
    sz[u]=1;
    cs[u][d%k]=1;
    for(int x: g[u])
    {
        if(x!=p)
        {
            dfs(x,u,d+1);
            sz[u]+=sz[x];
            for(int i=0;i<k;i++) for(int j=0;j<k;j++)
                ans+= (long long)to_add(i+j,2*d)*cs[u][i]*cs[x][j];
            for(int i=0;i<k;i++) cs[u][i]+=cs[x][i];
        }
    }
    ans+=(long long)sz[u]*(n-sz[u]);
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int x,y; cin>>n>>k;
    for(int i=1;i<n;i++)
    {
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1,0,0);
    cout<<ans/k;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> g[200005];
int cs[200005][6];
int sz[200005];
long long ans;
int n,k;

int to_add(int x,int y)
{
    int val = ((x-y)%k+k)%k;
    if(val==0) return 0;
    return k-val;
}

void dfs(int u,int p,int d)
{
    sz[u]=1;
    cs[u][d%k]=1;
    for(int x: g[u])
    {
        if(x!=p)
        {
            dfs(x,u,d+1);
            sz[u]+=sz[x];
            for(int i=0;i<k;i++) for(int j=0;j<k;j++)
                ans+= (long long)to_add(i+j,2*d)*cs[u][i]*cs[x][j];
            for(int i=0;i<k;i++) cs[u][i]+=cs[x][i];
        }
    }
    ans+=sz[u]*(n-sz[u]);
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int x,y; cin>>n>>k;
    for(int i=1;i<n;i++)
    {
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1,0,0);
    cout<<ans/k;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <unordered_set>

using namespace std;

typedef unsigned long long ull;
typedef unsigned int uint;

struct Node {
    ull s[5];
    ull k[5];
    ull t;
    vector<uint> n;
};

struct Qelt {
    uint n = 0;
    uint c = 0;
    uint p = 0;
    Qelt(uint n) : n(n), p(-1) {}
    Qelt(uint n, uint p) : n(n), p(p) {}
};

int main(int argc, char *argv[])
{
    #ifdef Debug
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout);
    #endif
    uint n, k;
    cin >> n >> k;
    vector<Node> a(n);
    for (uint i = 1; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        a[x].n.push_back(y);
        a[y].n.push_back(x);
    }
    vector<Qelt> q;
    q.emplace_back(0);
    while (!q.empty()) {
        Qelt &e = q.back();
        Node &v = a[e.n];
        if (e.c < v.n.size()) {
            uint t = v.n[e.c];
            ++e.c;
            if (t != e.p) {
                q.emplace_back(t, e.n);
            }
        } else {
            v.t = 0;
            for (uint i = 0; i < k; ++i) {
                v.s[i] = v.k[i] = 0;
            }
            for (uint i : v.n) {
                if (i != e.p) {
                    Node &w = a[i];
                    for (uint x = 0; x < k; ++x) {
                        for (uint y = 0; y < k; ++y) {
                            v.t += v.k[x] * w.s[y] + v.s[x] * w.k[y] + v.k[x] * w.k[y] * ((x + y + k - 1) / k);
                        }
                        v.k[x] += w.k[x];
                        v.s[x] += w.s[x];
                    }
                    v.t += w.t;
                }
            }
            for (uint x = 1; x < k; ++x) {
                v.t += v.k[x] + v.s[x];
            }
            v.t += v.s[0];
            uint ts = v.s[k - 1], tk = v.k[k - 1];
            for (uint i = k - 1; i > 0; --i) {
                v.s[i] = v.s[i - 1];
                v.k[i] = v.k[i - 1];
            }
            v.s[0] = ts + tk;
            v.k[0] = tk;
            ++v.k[1];
            q.pop_back();
        }
    }
    cout << (a[0].t) << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <unordered_set>

using namespace std;

typedef unsigned long long ull;
typedef unsigned int uint;

struct Node {
    ull s[5];
    ull k[5];
    ull t;
    vector<uint> n;
};

struct Qelt {
    uint n = 0;
    uint c = 0;
    uint p = 0;
    Qelt(uint n) : n(n), p(-1) {}
    Qelt(uint n, uint p) : n(n), p(p) {}
};

int main(int argc, char *argv[])
{
    #ifdef Debug
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout);
    #endif
    uint n, k;
    cin >> n >> k;
    vector<Node> a(n);
    for (uint i = 1; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        a[x].n.push_back(y);
        a[y].n.push_back(x);
    }
    vector<Qelt> q;
    q.emplace_back(0);
    while (!q.empty()) {
        Qelt &e = q.back();
        Node &v = a[e.n];
        if (e.c < v.n.size()) {
            uint t = v.n[e.c];
            ++e.c;
            if (t != e.p) {
                q.emplace_back(t, e.n);
            }
        } else {
            v.t = 0;
            for (uint i = 0; i < k; ++i) {
                v.s[i] = v.k[i] = 0;
            }
            for (uint i : v.n) {
                if (i != e.p) {
                    Node &w = a[i];
                    for (uint x = 0; x < k; ++x) {
                        for (uint y = 0; y < k; ++y) {
                            v.t += v.k[x] * w.s[y] + v.s[x] * w.k[y] + v.k[x] * w.k[y] * ((x + y + k - 1) / k);
                        }
                        v.k[x] += w.k[x];
                        v.s[x] += w.s[x];
                    }
                    v.t += w.t;
                }
            }
            for (uint x = 1; x < k; ++x) {
                v.t += v.k[x] + v.s[x];
            }
            v.t += v.s[0];
            if (k > 1) {
                ull ts = v.s[k - 1], tk = v.k[k - 1];
                for (uint i = k - 1; i > 0; --i) {
                    v.s[i] = v.s[i - 1];
                    v.k[i] = v.k[i - 1];
                }
                v.s[0] = ts + tk;
                v.k[0] = tk;
                ++v.k[1];
            } else {
                ++v.k[0];
                v.s[0] += v.k[0];
            }
            q.pop_back();
        }
    }
    cout << (a[0].t) << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <unordered_set>

using namespace std;

typedef unsigned long long ull;
typedef unsigned int uint;

struct Node {
    ull s[5];
    ull k[5];
    ull t;
    vector<uint> n;
};

struct Qelt {
    uint n = 0;
    uint c = 0;
    uint p = 0;
    Qelt(uint n) : n(n), p(-1) {}
    Qelt(uint n, uint p) : n(n), p(p) {}
};

int main(int argc, char *argv[])
{
    #ifdef Debug
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout);
    #endif
    uint n, k;
    cin >> n >> k;
    vector<Node> a(n);
    for (uint i = 1; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        a[x].n.push_back(y);
        a[y].n.push_back(x);
    }
    vector<Qelt> q;
    q.emplace_back(0);
    while (!q.empty()) {
        Qelt &e = q.back();
        Node &v = a[e.n];
        if (e.c < v.n.size()) {
            uint t = v.n[e.c];
            ++e.c;
            if (t != e.p) {
                q.emplace_back(t, e.n);
            }
        } else {
            v.t = 0;
            for (uint i = 0; i < k; ++i) {
                v.s[i] = v.k[i] = 0;
            }
            for (uint i : v.n) {
                if (i != e.p) {
                    Node &w = a[i];
                    for (uint x = 0; x < k; ++x) {
                        for (uint y = 0; y < k; ++y) {
                            v.t += v.k[x] * w.s[y] + v.s[x] * w.k[y] + v.k[x] * w.k[y] * ((x + y + k - 1) / k);
                        }
                        v.k[x] += w.k[x];
                        v.s[x] += w.s[x];
                    }
                    v.t += w.t;
                }
            }
            for (uint x = 1; x < k; ++x) {
                v.t += v.k[x] + v.s[x];
            }
            v.t += v.s[0];
            if (k > 1) {
                uint ts = v.s[k - 1], tk = v.k[k - 1];
                for (uint i = k - 1; i > 0; --i) {
                    v.s[i] = v.s[i - 1];
                    v.k[i] = v.k[i - 1];
                }
                v.s[0] = ts + tk;
                v.k[0] = tk;
                ++v.k[1];
            } else {
                ++v.k[0];
                v.s[0] += v.k[0];
            }
            q.pop_back();
        }
    }
    cout << (a[0].t) << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 2e5 + 10;
const int inf = 1e9 + 10;

int n, k;
vector<int> g[N];
ll c[N][5];
ll d[N][5];
ll res = 0;

void merge(int v, int to) {
    for(int i = 0; i < k; ++i) {
        for(int j = 0; j < k; ++j) {
            ll cnt = (ll)c[v][i] * c[to][j];
            ll t = (i + j + k - 1) / k;
            res += t * cnt;
        }
    }
    ll tot = 0;
    for(int i = 0; i < k; ++i) {
        tot += c[to][i];
    }
    for(int i = 0; i < k; ++i) {
        res += d[v][i] * tot;
    }
    tot = 0;
    for(int i = 0; i < k; ++i) {
        tot += c[v][i];
    }
    for(int i = 0; i < k; ++i) {
        res += d[to][i] * tot;
    }
    for(int i = 0; i < k; ++i) {
        d[v][i] += d[to][i];
        c[v][i] += c[to][i];
    }
}

void upd(int v) {
    int ck = c[v][k - 1];
    int dk = d[v][k - 1];
    for(int i = k - 1; i > 0; --i) {
        d[v][i] = d[v][i - 1];
        c[v][i] = c[v][i - 1];
    }
    c[v][0] = ck;
    d[v][0] = dk + ck;
}

void dfs(int v, int p) {
    c[v][0] = 1;
    for(const auto &to : g[v]) {
        if ( to == p ) continue;
        dfs(to, v);
        merge(v, to);
    }
    upd(v);
}

void solve() {
    scanf("%d%d",&n,&k);
    for(int i = 0; i < n - 1; ++i) {
        int a, b;
        scanf("%d%d",&a,&b);
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0, 0);
    printf("%lld\n", res);
}

int main() {
    // freopen("input.txt", "r", stdin);
    solve();

    return 0;
}


#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
using namespace std;

typedef complex<double> base;
typedef vector<base> vb;
typedef pair<int, int> pii;
typedef long long ll;

const double pi = acos(-1);
const int N = 2e5 + 10;
const ll mod = 1e9 + 7;
vector<int> gr[N];
int level[N];

int rev (int num, int lg_n) {
    int res = 0;
    for (int i=0; i<lg_n; ++i)
        if (num & (1<<i))
            res |= 1<<(lg_n-1-i);
    return res;
}

void fft (vector<base> & a, bool invert) {
    int n = (int) a.size();
    int lg_n = 0;
    while ((1 << lg_n) < n)  ++lg_n;

    for (int i=0; i<n; ++i)
        if (i < rev(i,lg_n))
            swap (a[i], a[rev(i,lg_n)]);

    for (int len=2; len<=n; len<<=1) {
        double ang = 2*pi/len * (invert ? -1 : 1);
        base wlen (cos(ang), sin(ang));
        for (int i=0; i<n; i+=len) {
            base w (1);
            for (int j=0; j<len/2; ++j) {
                base u = a[i+j],  v = a[i+j+len/2] * w;
                a[i+j] = u + v;
                a[i+j+len/2] = u - v;
                w *= wlen;
            }
        }
    }
    if (invert)
        for (int i=0; i<n; ++i)
            a[i] /= n;
}

void mult1(const vector<ll>& a, const vector<ll>& b, vector<ll>& res) {
    int n = 1;
    while( n < (int)max(a.size(), b.size())) n *= 2;
    n *= 2;

    vb fa(n), fb(n);
    for(int i = 0; i < (int)a.size(); ++i) {
        fa[i] = a[i];
    }
    for(int i = 0; i < (int)b.size(); ++i) {
        fb[i] = b[i];
    }

    fft(fa, 0);
    fft(fb, 0);
    for(int i = 0; i < n; ++i) {
        fa[i] *= fb[i];
    }
    fft(fa, 1);

    res.resize(n, 0);
    for(int i = 0; i < n; ++i) {
        res[i] = ((ll)floor(fa[i].real() + 0.5)) % mod;
    }
}

int dfs_build(int v, int size, int& center, int p) {
    int sum = 1;
    for(int& x : gr[v] ) {
        if ( center != -1 ) return sum;
        if ( level[x] == -1 && x != p ) {
            int t = dfs_build(x, size, center, v);
            sum += t;
        }
    }
    if ( center == -1 && (2 * sum >= size || p == -1) )
        center = v;
    return sum ;
}

void centroid(int v , int size , int depth) {
    int center = -1;
    dfs_build(v, size, center, v);
    if ( center == -1 ) {
        center = v;
        level[center] = depth;
    }
    assert(center != -1);
    level[center] = depth;
    for(int& x : gr[center] ) {
        if ( level[x] == -1 ) {
            centroid(x , size / 2 , depth + 1) ;
        }
    }
}

int dfs_depth_vert(int v, int mxlvl, int p) {
    if ( mxlvl >= level[v] ) return 0;
    int res = 0;
    for(auto to : gr[v]) {
        if ( to == p ) continue;
        res = max(dfs_depth_vert(to, mxlvl, v), res);
    }
    return res + 1;
}

void dfs_cnt(int v, int mxlvl, int dep, vector<ll>& d, int p) {
    if ( mxlvl >= level[v] ) return;
    d[++dep]++;
    for(auto to : gr[v]) {
        if ( to == p ) continue;
        dfs_cnt(to, mxlvl, dep, d, v);
    }
}

vector<ll> d[N];
vector<ll> answer(N, 0);
vector<ll> sum;
vector<ll> res_mult;
vector<pii> order;

void sol(int v) {
    order.clear();
    sum.clear();
    int mxsz = 0;
    for(int i = 0; i < (int)gr[v].size(); ++i) {
        int to = gr[v][i];
        d[i].clear();
        int sz = dfs_depth_vert(to, level[v], v);
        mxsz = max(sz, mxsz);
        d[i].resize(sz + 1, 0);
        dfs_cnt(to, level[v], 0, d[i], v);
        order.push_back( {sz, i} );
    }
    if ( order.empty() ) return;
    sort(ALL(order));

    sum.resize( mxsz + 1, 0 );
    for(int i = 0; i < (int)order.size() - 1; ++i) {
        int it1 = order[i].second;
        for(int j = 0; j < min(N,(int)d[it1].size()); ++j) {
            sum[j] = (sum[j] + d[it1][j]) % mod;
            answer[j] = (answer[j] + d[it1][j]) % mod;
        }
        int it2 = order[i + 1].second;
        mult1(sum, d[it2], res_mult);
        for(int j = 0; j < min(N,(int)res_mult.size()); ++j) {
            answer[j] = (answer[j] + res_mult[j]) % mod;
        }
    }
    for(int j = 0; j < min(N,(int)d[order.back().second].size()); ++j) {
        answer[j] = (answer[j] + d[ order.back().second ][j]) % mod;
    }
}

bool solve() {
    srand(time(0));
    int n, k;
    if ( scanf("%d%d", &n,&k) != 2 ) return 0;
    for(int i = 0; i < n - 1; ++i) {
        int x, y;
        scanf("%d%d",&x,&y);
        --x, --y;
        gr[x].push_back(y);
        gr[y].push_back(x);
    }

    for(int i = 0; i < N; ++i) {
        level[i] = -1;
    }

    centroid(rand() % n, n, 0);
    for(int i = 0; i < n; ++i) {
        sol(i);
    }

    ll res = 0;
    for(int i = 1; i <= n; ++i) {
        if ( answer[i] == 0 ) break;
        int t = (i + k - 1) / k;
        res += t * answer[i];
    }
    printf("%lld\n", res);
    return 1;
}

int main() {
    // freopen("input.txt", "r", stdin);
    solve();

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 2e5 + 10;
const int inf = 1e9 + 10;

int n, k;
vector<int> g[N];
int c[N][5];
int d[N][5];
ll res = 0;

void merge(int v, int to) {
    for(int i = 0; i < k; ++i) {
        for(int j = 0; j < k; ++j) {
            ll cnt = (ll)c[v][i] * c[to][j];
            ll t = (i + j + k - 1) / k;
            res += t * cnt;
        }
    }
    ll tot = 0;
    for(int i = 0; i < k; ++i) {
        tot += c[to][i];
    }
    for(int i = 0; i < k; ++i) {
        res += d[v][i] * tot;
    }
    tot = 0;
    for(int i = 0; i < k; ++i) {
        tot += c[v][i];
    }
    for(int i = 0; i < k; ++i) {
        res += d[to][i] * tot;
    }
    for(int i = 0; i < k; ++i) {
        d[v][i] += d[to][i];
        c[v][i] += c[to][i];
    }
}

void upd(int v) {
    int ck = c[v][k - 1];
    int dk = d[v][k - 1];
    for(int i = k - 1; i > 0; --i) {
        d[v][i] = d[v][i - 1];
        c[v][i] = c[v][i - 1];
    }
    c[v][0] = ck;
    d[v][0] = dk + ck;
}

void dfs(int v, int p) {
    c[v][0] = 1;
    for(const auto &to : g[v]) {
        if ( to == p ) continue;
        dfs(to, v);
        merge(v, to);
    }
    upd(v);
}

void solve() {
    scanf("%d%d",&n,&k);
    for(int i = 0; i < n - 1; ++i) {
        int a, b;
        scanf("%d%d",&a,&b);
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0, 0);
    printf("%lld\n", res);
}

int main() {
    // freopen("input.txt", "r", stdin);
    solve();

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 2e5 + 10;
const int inf = 1e9 + 10;

int n, k;
vector<int> g[N];
ll c[N][5];
ll d[N][5];
ll res = 0;

void merge(int v, int to) {
    for(int i = 0; i < k; ++i) {
        for(int j = 0; j < k; ++j) {
            ll cnt = (ll)c[v][i] * c[to][j];
            ll t = (i + j + k - 1) / k;
            res += t * cnt;
        }
    }
    ll tot = 0;
    for(int i = 0; i < k; ++i) {
        tot += c[to][i];
    }
    for(int i = 0; i < k; ++i) {
        res += d[v][i] * tot;
    }
    tot = 0;
    for(int i = 0; i < k; ++i) {
        tot += c[v][i];
    }
    for(int i = 0; i < k; ++i) {
        res += d[to][i] * tot;
    }
    for(int i = 0; i < k; ++i) {
        d[v][i] += d[to][i];
        c[v][i] += c[to][i];
    }
}

void upd(int v) {
    ll ck = c[v][k - 1];
    ll dk = d[v][k - 1];
    for(int i = k - 1; i > 0; --i) {
        d[v][i] = d[v][i - 1];
        c[v][i] = c[v][i - 1];
    }
    c[v][0] = ck;
    d[v][0] = dk + ck;
}

void dfs(int v, int p) {
    c[v][0] = 1;
    for(const auto &to : g[v]) {
        if ( to == p ) continue;
        dfs(to, v);
        merge(v, to);
    }
    upd(v);
}

void solve() {
    scanf("%d%d",&n,&k);
    for(int i = 0; i < n - 1; ++i) {
        int a, b;
        scanf("%d%d",&a,&b);
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0, 0);
    printf("%lld\n", res);
}

int main() {
    // freopen("input.txt", "r", stdin);
    solve();

    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define __FastIO                                                               \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);
#define D cout << "ok" << endl;
#define _(x) cout << #x << "->" << x;
#define _n cout<<endl;
#define __ cout<<" ";
#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)
#define LOG2(x)                                                           \
  (sizeof(unsigned long) * 8 - 1 - __builtin_clzl((unsigned long)(x)))
#define LOG2_UP(x)                                                        \
  (((x) - (1 << FAST_LOG2(x))) ? FAST_LOG2(x) + 1 : FAST_LOG2(x))
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define FIN freopen("in", "r", stdin);
#define FOUT freopen("out", "w", stdout);
#define zero(b) memset(b,0,sizeof b);
#define mone(b) memset(b,-1,sizeof b);
#define gcd(a,b) __gcd(a,b)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<db, db> pdd;
template <typename T> using ordered_set = tree<T, null_type, less<T>,
                            rb_tree_tag, tree_order_statistics_node_update>;
const int sz=200000+2;
int n,k;

vector<int> g[sz];
ll nodes[sz];
ll mm[sz][6];
ll sum=0;

ll dfs(int u,int par,int depth)
{
    nodes[u]=1;
    mm[u][depth%k]=1;
    for(auto v:g[u])
    {
        if(v!=par)
        {
            dfs(v,u,depth+1);
            nodes[u]+=nodes[v];
            for(int i=0; i<k; i++)
            {
                for(int j=0; j<k; j++)
                {
                    int distance=(((i+j)-2*depth)%k+k)%k;
                    distance=((k-distance)%k+k)%k;
                    sum+=distance*mm[u][i]*mm[v][j];
                }
            }

            for(int i=0; i<k; i++)
                mm[u][i]+=mm[v][i];
        }
    }
    sum+=nodes[u]*(n-nodes[u]);

}
int main()
{
    cin>>n>>k;
    for(int i=1; i<n; i++)
    {
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    dfs(1,-1,0);
    cout<<sum/k<<endl;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define __FastIO                                                               \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);
#define D cout << "ok" << endl;
#define _(x) cout << #x << "->" << x;
#define _n cout<<endl;
#define __ cout<<" ";
#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)
#define LOG2(x)                                                           \
  (sizeof(unsigned long) * 8 - 1 - __builtin_clzl((unsigned long)(x)))
#define LOG2_UP(x)                                                        \
  (((x) - (1 << FAST_LOG2(x))) ? FAST_LOG2(x) + 1 : FAST_LOG2(x))
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define FIN freopen("in", "r", stdin);
#define FOUT freopen("out", "w", stdout);
#define zero(b) memset(b,0,sizeof b);
#define mone(b) memset(b,-1,sizeof b);
#define gcd(a,b) __gcd(a,b)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<db, db> pdd;
template <typename T> using ordered_set = tree<T, null_type, less<T>,
                            rb_tree_tag, tree_order_statistics_node_update>;
const int sz=200000+2;
int n,k;

vector<int> g[sz];
ll nodes[sz];
ll mm[sz][6];
ll sum=0;

ll dfs(int u,int par,int depth)
{
    nodes[u]=1;
    mm[u][depth%k]=1;
    for(auto v:g[u])
    {
        if(v!=par)
        {
            dfs(v,u,depth+1);
            nodes[u]+=nodes[v];
            for(int i=0; i<k; i++)
            {
                for(int j=0; j<k; j++)
                {
                    int distance=(((i+j)-2*depth)%k+k)%k;
                    distance=((k-distance)%k+k)%k;
                    sum+=distance*mm[u][j]*mm[v][i];
                }
            }

            for(int i=0; i<k; i++)
                mm[u][i]+=mm[v][i];
        }
    }
    sum+=nodes[u]*(n-nodes[u]);

}
int main()
{
    cin>>n>>k;
    for(int i=1; i<n; i++)
    {
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    dfs(1,-1,0);
    cout<<sum/k<<endl;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <vector>
using namespace std;

namespace zuiyt
{
	template<typename T>
	inline void read(T &x)
	{
		bool f = false;
		char c;
		x = 0;
		do
			c = getchar();
		while (c != '-' && !isdigit(c));
		if (c == '-')
			f = true, c = getchar();
		do
			x = x * 10 + c - '0', c = getchar();
		while (isdigit(c));
		if (f)
			x = -x;
	}
	template<typename T>
	inline void write(T x)
	{
		static char buf[20];
		char *pos = buf;
		if (x < 0)
			putchar('-'), x = -x;
		do
			*pos++ = x % 10 + '0';
		while (x /= 10);
		while (pos > buf)
			putchar(*--pos);
	}
	typedef long long ll;
	const int N = 2e5 + 10, K = 5, INF = 0x3f3f3f3f;
	int n, k, size[N];
	ll num[K];
	vector<int> g[N];
	namespace Point_Divide
	{
		int f[N], sum, rot, dis[N], cnt;
		bool vis[N];
		void get_rot(const int u, const int fa)
		{
			f[u] = 0;
			size[u] = 1;
			for (int i = 0; i < g[u].size(); i++)
			{
				int v = g[u][i];
				if (v == fa || vis[v])
					continue;
				get_rot(v, u);
				size[u] += size[v];
				f[u] = max(f[u], size[v]);
			}
			f[u] = max(f[u], sum - f[u]);
			if (f[u] < f[rot])
				rot = u;
		}
		void get_dis(const int u, const int fa, const int d, const int p)
		{
			dis[cnt++] = d;
			for (int i = 0; i < g[u].size(); i++)
			{
				int v = g[u][i];
				if (v == fa || vis[v])
					continue;
				get_dis(v, u, (d + 1) % p, p);
			}
		}
		void cal(ll *ans, const int u, const int d, const int p)
		{
			ll tmp[K] = {0};
			memset(ans, 0, sizeof(ll[p]));
			cnt = 0;
			get_dis(u, 0, d, p);
			for (int i = 0; i < cnt; i++)
				++tmp[dis[i]];
			for (int i = 0; i < p; i++)
				for (int j = 0; j < p; j++)
					ans[i] += tmp[j] * tmp[(i - j + p) % p];
		}
		void solve(const int u, const int p)
		{
			ll tmp[K];
			vis[u] = true;
			cal(tmp, u, 0, p);
			for (int i = 0; i < p; i++)
				num[i] += tmp[i];
			for (int i = 0; i < g[u].size(); i++)
			{
				int v = g[u][i];
				if (vis[v])
					continue;
				cal(tmp, v, 1, p);
				for (int i = 0; i < p; i++)
					num[i] -= tmp[i];
				rot = 0, sum = size[v];
				get_rot(v, 0);
				solve(rot, p);
			}
		}
		ll work(const int p)
		{
			ll ans = 0;
			f[0] = INF, sum = n;
			get_rot(1, 0);
			solve(rot, p);
			for (int i = 1; i < p; i++)
				ans += (ll)(p - i) * num[i] / 2;
			return ans;
		}
	}
	ll dfs(const int u, const int f)
	{
		ll ans = 0;
		size[u] = 1;
		for (int i = 0; i < g[u].size(); i++)
		{
			int v = g[u][i];
			if (v == f)
				continue;
			ans += dfs(v, u);
			size[u] += size[v];
			ans += (ll)size[v] * (n - size[v]);
		}
		return ans;
	}
	int work()
	{
		read(n), read(k);
		Point_Divide::f[0] = INF;
		for (int i = 1; i < n; i++)
		{
			int u, v;
			read(u), read(v);
			g[u].push_back(v);
			g[v].push_back(u);
		}
		write((dfs(1, 0) + Point_Divide::work(k)) / k);
		return 0;
	}
}
int main()
{
	return zyt::work();
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <vector>
using namespace std;

namespace zyt
{
	template<typename T>
	inline void read(T &x)
	{
		bool f = false;
		char c;
		x = 0;
		do
			c = getchar();
		while (c != '-' && !isdigit(c));
		if (c == '-')
			f = true, c = getchar();
		do
			x = x * 10 + c - '0', c = getchar();
		while (isdigit(c));
		if (f)
			x = -x;
	}
	template<typename T>
	inline void write(T x)
	{
		static char buf[20];
		char *pos = buf;
		if (x < 0)
			putchar('-'), x = -x;
		do
			*pos++ = x % 10 + '0';
		while (x /= 10);
		while (pos > buf)
			putchar(*--pos);
	}
	typedef long long ll;
	const int N = 2e5 + 10, K = 5, INF = 0x3f3f3f3f;
	int n, k, size[N];
	ll num[K];
	vector<int> g[N];
	namespace Point_Divide
	{
		int f[N], sum, rot, dis[N], cnt;
		bool vis[N];
		void get_rot(const int u, const int fa)
		{
			f[u] = 0;
			size[u] = 1;
			for (int i = 0; i < g[u].size(); i++)
			{
				int v = g[u][i];
				if (v == fa || vis[v])
					continue;
				get_rot(v, u);
				size[u] += size[v];
				f[u] = max(f[u], size[v]);
			}
			f[u] = max(f[u], sum - f[u]);
			if (f[u] < f[rot])
				rot = u;
		}
		void get_dis(const int u, const int fa, const int d, const int p)
		{
			dis[cnt++] = d;
			for (int i = 0; i < g[u].size(); i++)
			{
				int v = g[u][i];
				if (v == fa || vis[v])
					continue;
				get_dis(v, u, (d + 1) % p, p);
			}
		}
		void cal(ll *ans, const int u, const int d, const int p)
		{
			ll tmp[K] = {0};
			memset(ans, 0, sizeof(ll[p]));
			cnt = 0;
			get_dis(u, 0, d, p);
			for (int i = 0; i < cnt; i++)
				++tmp[dis[i]];
			for (int i = 0; i < p; i++)
				for (int j = 0; j < p; j++)
					ans[i] += tmp[j] * tmp[(i - j + p) % p];
		}
		void solve(const int u, const int p)
		{
			ll tmp[K];
			vis[u] = true;
			cal(tmp, u, 0, p);
			for (int i = 0; i < p; i++)
				num[i] += tmp[i];
			for (int i = 0; i < g[u].size(); i++)
			{
				int v = g[u][i];
				if (vis[v])
					continue;
				cal(tmp, v, 1, p);
				for (int i = 0; i < p; i++)
					num[i] -= tmp[i];
				rot = 0, sum = size[v];
				get_rot(v, 0);
				solve(rot, p);
			}
		}
		ll work(const int p)
		{
			ll ans = 0;
			f[0] = INF, sum = n;
			get_rot(1, 0);
			solve(rot, p);
			for (int i = 1; i < p; i++)
				ans += (ll)(p - i) * num[i] / 2;
			return ans;
		}
	}
	ll dfs(const int u, const int f)
	{
		ll ans = 0;
		size[u] = 1;
		for (int i = 0; i < g[u].size(); i++)
		{
			int v = g[u][i];
			if (v == f)
				continue;
			ans += dfs(v, u);
			size[u] += size[v];
			ans += (ll)size[v] * (n - size[v]);
		}
		return ans;
	}
	int work()
	{
		read(n), read(k);
		Point_Divide::f[0] = INF;
		for (int i = 1; i < n; i++)
		{
			int u, v;
			read(u), read(v);
			g[u].push_back(v);
			g[v].push_back(u);
		}
		write((dfs(1, 0) + Point_Divide::work(k)) / k);
		return 0;
	}
}
int main()
{
	return zyt::work();
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <vector>
using namespace std;

namespace zuiyt
{
    template<typename T>
    inline void read(T &x)
    {
        bool f = false;
        char c;
        x = 0;
        do
            c = getchar();
        while (c != '-' && !isdigit(c));
        if (c == '-')
            f = true, c = getchar();
        do
            x = x * 10 + c - '0', c = getchar();
        while (isdigit(c));
        if (f)
            x = -x;
    }
    template<typename T>
    inline void write(T x)
    {
        static char buf[20];
        char *pos = buf;
        if (x < 0)
            putchar('-'), x = -x;
        do
            *pos++ = x % 10 + '0';
        while (x /= 10);
        while (pos > buf)
            putchar(*--pos);
    }
    typedef long long ll;
    const int N = 2e5 + 10, K = 5, INF = 0x3f3f3f3f;
    int n, k, size[N];
    ll num[K];
    vector<int> g[N];
    namespace Point_Divide
    {
        int f[N], sum, rot, dis[N], cnt;
        bool vis[N];
        void get_rot(const int u, const int fa)
        {
            f[u] = 0;
            size[u] = 1;
            for (int i = 0; i < g[u].size(); i++)
            {
                int v = g[u][i];
                if (v == fa || vis[v])
                    continue;
                get_rot(v, u);
                size[u] += size[v];
                f[u] = max(f[u], size[v]);
            }
            f[u] = max(f[u], sum - f[u]);
            if (f[u] < f[rot])
                rot = u;
        }
        void get_dis(const int u, const int fa, const int d, const int p)
        {
            dis[cnt++] = d;
            for (int i = 0; i < g[u].size(); i++)
            {
                int v = g[u][i];
                if (v == fa || vis[v])
                    continue;
                get_dis(v, u, (d + 1) % p, p);
            }
        }
        void cal(ll *ans, const int u, const int d, const int p)
        {
            ll tmp[K] = {0};
            memset(ans, 0, sizeof(ll[p]));
            cnt = 0;
            get_dis(u, 0, d, p);
            for (int i = 0; i < cnt; i++)
                ++tmp[dis[i]];
            for (int i = 0; i < p; i++)
                for (int j = 0; j < p; j++)
                    ans[i] += tmp[j] * tmp[(i - j + p) % p];
        }
        void solve(const int u, const int p)
        {
            ll tmp[K];
            vis[u] = true;
            cal(tmp, u, 0, p);
            for (int i = 0; i < p; i++)
                num[i] += tmp[i];
            for (int i = 0; i < g[u].size(); i++)
            {
                int v = g[u][i];
                if (vis[v])
                    continue;
                cal(tmp, v, 1, p);
                for (int i = 0; i < p; i++)
                    num[i] -= tmp[i];
                rot = 0, sum = size[v];
                get_rot(v, 0);
                solve(rot, p);
            }
        }
        ll work(const int p)
        {
            ll ans = 0;
            f[0] = INF, sum = n;
            get_rot(1, 0);
            solve(rot, p);
            for (int i = 1; i < p; i++)
                ans += (ll)(p - i) * num[i] / 2;
            return ans;
        }
    }
    ll dfs(const int u, const int f)
    {
        ll ans = 0;
        size[u] = 1;
        for (int i = 0; i < g[u].size(); i++)
        {
            int v = g[u][i];
            if (v == f)
                continue;
            ans += dfs(v, u);
            size[u] += size[v];
            ans += (ll)size[v] * (n - size[v]);
        }
        return ans;
    }
    int work()
    {
        read(n), read(k);
        Point_Divide::f[0] = INF;
        for (int i = 1; i < n; i++)
        {
            int u, v;
            read(u), read(v);
            g[u].push_back(v);
            g[v].push_back(u);
        }
        write((dfs(1, 0) + Point_Divide::work(k)) / k);
        return 0;
    }
}
int main()
{
    return zuiyt::work();
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5;
int n,k;
vector<int>g[N];
map<int,int>mp[N],res;
void dfs(int u,int p){
    mp[u][0]++;

    for(auto v : g[u]){
        if(v == p)continue;
        dfs(v,u);
        for(auto it : mp[u]){
            for(auto it1 : mp[v]){
                res[it.first + it1.first + 1] += it.second * it1.second;
            }
        }
        for(auto it : mp[v]){
            mp[u][it.first + 1] += it.second;
        }
    }

   // cout<<u<<endl;

  /*  for(auto it:mp[u]){
        cout<<it.first<<' '<<it.second<<endl;
        //res[it.first] += it.second;
    }*/
}
signed main()
{
    int i,u,v;
    ios_base::sync_with_stdio(0);
    cin>>n>>k;

    for(i=1;i<n;i++){
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    dfs(1,0);
    long long ans = 0;
   // cout<<"res\n";
    for(auto it : res){
        if(it.first == 0)continue;
       // cout<<it.first<<' '<<it.second<<endl;
        ans += (it.first / k + ((it.first % k) != 0)) * it.second;
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5;
int n,k;
vector<int>g[N];
unordered_map<int,int>mp[N],res;
void dfs(int u,int p){
    mp[u][0]++;

    for(auto v : g[u]){
        if(v == p)continue;
        dfs(v,u);
        for(auto it : mp[u]){
            for(auto it1 : mp[v]){
                res[it.first + it1.first + 1] += it.second * it1.second;
            }
        }
        for(auto it : mp[v]){
            mp[u][it.first + 1] += it.second;
        }
        mp[v].clear();
    }

   // cout<<u<<endl;

  /*  for(auto it:mp[u]){
        cout<<it.first<<' '<<it.second<<endl;
        //res[it.first] += it.second;
    }*/
}
signed main()
{
    int i,u,v;
    ios_base::sync_with_stdio(0);
    cin>>n>>k;

    for(i=1;i<n;i++){
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    dfs(1,0);
    long long ans = 0;
   // cout<<"res\n";
    for(auto it : res){
        if(it.first == 0)continue;
       // cout<<it.first<<' '<<it.second<<endl;
        ans += (it.first / k + ((it.first % k) != 0)) * it.second;
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5;
int n,k,a[N];
vector<int>g[N],vv[N];
void dfs(int u,int p){

    int i,j,m1=0,m2=0;
    for(auto v : g[u]){
       if(v == p)continue;
        dfs(v,u);
        if(vv[v].size()>m2){
            m2 = vv[v].size();
            if(m2 > m1) swap(m1,m2);
        }
    }
    vv[u].resize(m1+m2+3,0);
    vv[u][0]++;
    for(auto v : g[u]){
        if(v == p)continue;
        for(int i = 0;i<vv[u].size();i++){
            if(vv[u][i]==0)break;
            for(int j = 0;j<vv[v].size();j++){
                a[i + j + 1] += vv[u][i] * vv[v][j];
            }
        }
        for(int j = 0;j<vv[v].size();j++){
                vv[u][j + 1] += vv[v][j];
        }
        vv[v].clear();
    }

   // cout<<"fff"<<u<<endl;

  /*  for(auto it:vv[u]){
        cout<<it<<' ';
        //res[it.first] += it.second;
    }
    cout<<endl;*/
}
signed main()
{
    int i,u,v;
    ios_base::sync_with_stdio(0);
    cin>>n>>k;

    for(i=1;i<n;i++){
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    memset(a,0,sizeof a);
    dfs(1,0);
    long long ans = 0;
     for(int j = 1;j<N;j++){
         if(a[j] == 0)break;
         ans += (j/k + (j%k != 0)) * a[j];
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5;
int n,k,ans,a[N][5],ts[N];
vector<int>g[N];
void dfs(int u,int p,int d){
    ts[u] = a[u][d%k] = 1;
    int i,j;
    for(auto v : g[u]){
       if(v == p)continue;
        dfs(v,u,d+1);
        for(i=0;i<k;i++){
            for(j=0;j<k;j++){
                int x = (k - (i + j - 2 * (d%k))%k)%k;
                ans += x * a[u][i] * a[v][j];
            }
        }
        for(i=0;i<k;i++)a[u][i] += a[v][i];
        ts[u] += ts[v];
    }
    ans += ts[u] * (n - ts[u]);
}
signed main()
{
    int i,u,v;
    ios_base::sync_with_stdio(0);
    cin>>n>>k;

    for(i=1;i<n;i++){
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1,0,0);
    cout<<ans/k;
    return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5;
int n,k,a[N];
vector<int>g[N],vv[N];
void dfs(int u,int p){

    int i,j,m1=0;
    for(auto v : g[u]){
       if(v == p)continue;
        dfs(v,u);
        if(vv[v].size()>m1){
            m1 = vv[v].size();
        }
    }
    vv[u].resize(m1+1,0);
    vv[u][0]++;
    for(auto v : g[u]){
        if(v == p)continue;
        for(int i = 0;i<vv[u].size();i++){
            if(vv[u][i]==0)break;
            for(int j = 0;j<vv[v].size();j++){
                a[i + j + 1] += vv[u][i] * vv[v][j];
            }
        }
        for(int j = 0;j<vv[v].size();j++){
                vv[u][j + 1] += vv[v][j];
        }
        vv[v].clear();
    }

   // cout<<"fff"<<u<<endl;

  /*  for(auto it:vv[u]){
        cout<<it<<' ';
        //res[it.first] += it.second;
    }
    cout<<endl;*/
}
signed main()
{
    int i,u,v;
    ios_base::sync_with_stdio(0);
    cin>>n>>k;

    for(i=1;i<n;i++){
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    memset(a,0,sizeof a);
    dfs(1,0);
    long long ans = 0;
     for(int j = 1;j<N;j++){
         if(a[j] == 0)break;
         ans += (j/k + (j%k != 0)) * a[j];
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5;
int n,k;
vector<int>g[N];
map<int,int>mp[N],res;
void dfs(int u,int p){
    mp[u][0]++;

    for(auto v : g[u]){
        if(v == p)continue;
        dfs(v,u);
        for(auto it : mp[u]){
            for(auto it1 : mp[v]){
                res[it.first + it1.first + 1] += it.second * it1.second;
            }
        }
        for(auto it : mp[v]){
            mp[u][it.first + 1] += it.second;
        }
    }

   // cout<<u<<endl;

  /*  for(auto it:mp[u]){
        cout<<it.first<<' '<<it.second<<endl;
        //res[it.first] += it.second;
    }*/
}
signed main()
{
    int i,u,v;
    cin>>n>>k;

    for(i=1;i<n;i++){
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    dfs(1,0);
    long long ans = 0;
   // cout<<"res\n";
    for(auto it : res){
        if(it.first == 0)continue;
       // cout<<it.first<<' '<<it.second<<endl;
        ans += (it.first / k + ((it.first % k) != 0)) * it.second;
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5;
int n,k;
vector<int>g[N];
map<int,int>mp[N],res;
void dfs(int u,int p){
    mp[u][0]++;

    for(auto v : g[u]){
        if(v == p)continue;
        dfs(v,u);
        for(auto it : mp[u]){
            for(auto it1 : mp[v]){
                res[it.first + it1.first + 1] += it.second * it1.second;
            }
        }
        for(auto it : mp[v]){
            mp[u][it.first + 1] += it.second;
        }
        mp[v].clear();
    }

   // cout<<u<<endl;

  /*  for(auto it:mp[u]){
        cout<<it.first<<' '<<it.second<<endl;
        //res[it.first] += it.second;
    }*/
}
signed main()
{
    int i,u,v;
    ios_base::sync_with_stdio(0);
    cin>>n>>k;

    for(i=1;i<n;i++){
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    dfs(1,0);
    long long ans = 0;
   // cout<<"res\n";
    for(auto it : res){
        if(it.first == 0)continue;
       // cout<<it.first<<' '<<it.second<<endl;
        ans += (it.first / k + ((it.first % k) != 0)) * it.second;
    }
    cout<<ans;
    return 0;
}