Diameter Counting
题号:NC225907
时间限制:C/C++/Rust/Pascal 4秒,其他语言8秒
空间限制:C/C++/Rust/Pascal 1024 M,其他语言2048 M
64bit IO Format: %lld

题目描述

Given a integer , you are asked to calculate the sum of the diameter of all unrooted labeled trees with nodes labeled from to . Here the diameter of a tree is the length of the longest simple path on this tree, and the length of a path is the number of edges along this path.

Since the answer may be too large, you only need to output the result modulo a given prime number .

输入描述:

The input contains two integers  and  , where  is a prime number. 

输出描述:

Output a single integer, indicating the sum of the diameter of all labeled trees with  nodes modulo .
示例1

输入

复制
2 998244353

输出

复制
1
示例2

输入

复制
4 1000000007

输出

复制
44
示例3

输入

复制
6 1000000009

输出

复制
5322