A good tree is a tree that satisfies both of these conditions.
- It has k×n nodes, numbered from 0 to k×n−1.
- Nodes i and j with 0≤i,j<k×n and i/k=j/k are not adjacent. Here / is integer division, so 7/2=3.
The second condition says that if you cut the numbers into n blocks of k consecutive values, no edge joins two nodes of the same block. Any other pair of nodes may be joined by an edge.
The nodes are labelled, so two trees with different edge sets count as different trees.
Given n and k, write a program that counts the good trees.