#abc220e. E - Distance on Large Perfect Binary Tree
E - Distance on Large Perfect Binary Tree
Score : points
问题描述
我们有一棵包含 个顶点的树。
这些顶点按顺序编号为 至 。对于每个 ,存在以下边:
- 一条无向边连接顶点 和顶点 ,
- 一条无向边连接顶点 和顶点 。
除此之外没有其他边。
设两个顶点之间的距离是连接这两个顶点的简单路径上的边数。
求满足顶点对 之间距离为 的数量模 后的结果。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have a tree with vertices.
The vertices are numbered through . For each , the following edges exist:
- an undirected edge connecting Vertex and Vertex ,
- an undirected edge connecting Vertex and Vertex .
There is no other edge.
Let the distance between two vertices be the number of edges in the simple path connecting those two vertices.
Find the number, modulo , of pairs of vertices such that the distance between them is .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3 2
Sample Output 1
14
The following figure describes the given tree.
There are pairs of vertices such that the distance between them is : $(1,4),(1,5),(1,6),(1,7),(2,3),(3,2),(4,1),(4,5),(5,1),(5,4),(6,1),(6,7),(7,1),(7,6)$.
Sample Input 2
14142 17320
Sample Output 2
11284501
update @ 2024/3/10 09:43:47