您的位置:首页 > 其它

2016CCPC东北地区大学生程序设计竞赛 - 重现赛 A - Minimum’s Revenge HDU 5922

2016-10-15 19:47 369 查看
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

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=100;
typedef long long LL;
int main()
{
LL n;
int T;
int t=1;
scanf("%d",&T);
while(T--){
scanf("%lld",&n);
printf("Case #%d: ",t++);
LL ans=(n+2)*(n-1)/2;
printf("%lld\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐