HDU5922-Minimum’s Revenge

来源:互联网 发布:手机淘宝改支付宝绑定 编辑:程序博客网 时间:2024/06/08 06:20

Minimum’s Revenge

                                                                              Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
                                                                                                         Total Submission(s): 1307    Accepted Submission(s): 681


Problem 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 multipleof 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 (T100), which indicates the number of test cases.

For each test case, the first line contains only one integer n (2n109), 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
223
 

Sample Output
Case #1: 2Case #2: 5
Hint
In the second sample, the graph contains 3 edges which are (1, 2, 2), (1, 3, 3) and (2, 3, 6). Thus the answer is 5.
 

Source
2016CCPC东北地区大学生程序设计竞赛 - 重现赛
 

Recommend
wange2014
 


题意:给你n个点,这些点之间添加n-1条边,形成一个不带环的树,边的权值为边连接的两点的乘积

解题思路:将所有不是1的点和1号点相连


#include <stdio.h>#include <stdlib.h>#include <string.h>#include <string>#include <math.h>#include <time.h>#include <algorithm>#include <vector>#include <stack>#include <queue>#include <map>#include <set>using namespace std;const int INF = 0x3f3f3f3f3f;#define LL long longint main(){int t,cas=0;scanf("%d", &t);while (t--){LL n;scanf("%lld", &n);printf("Case #%d: %lld\n",++cas, (2 + n)*(n - 1) / 2);}return 0;}