Description
There is a graph of n vertices which are indexed from 1 to n. For any pair of different vertices, the weight of the edge between them is the least common multiple of their indexes.
Mr. Frog is wondering about the total weight of the minimum spanning tree. Can you help him?
Input
The first line contains only one integer T (T≤100), which indicates the number of test cases.
For each test case, the first line contains only one integer n (2≤n≤109), indicating the number of vertices.
Output
For each test case, output one line “Case #x:y”,where x is the case number (starting from 1) and y is the total weight of the minimum spanning tree.
Sample Input
2
2
3
Sample Output
Case #1: 2
Case #2: 5
题意:给你一个完全图,然后每条边的权值是两端点标号的LCM
然后需要你构造一个最小生成树,使得权和最小
那么树保证每个点都是在树上的把,所以每个点都需要联通,
很容易想到和1连接的时候就是最小的,所以只需要每个点都和1相连
所以答案就是(n+2)*(n-1)/2

这是一个关于程序设计竞赛的问题,描述了一个包含n个顶点的图,每对不同顶点间边的权重是它们编号的最小公倍数。任务是计算最小生成树的总权重。样例输入和输出展示了如何处理小规模测试用例。解决策略是将每个顶点与编号为1的顶点连接,得到的权值总和即为答案,即(n+2)*(n-1)/2。
最低0.47元/天 解锁文章
1006

被折叠的 条评论
为什么被折叠?



