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
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; }
相关文章推荐
- HDU 5922 Minimum’s Revenge(思维题)——2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- (HDU 5922)Minimum’s Revenge 思维水题 <2016CCPC东北地区大学生程序设计竞赛 - 重现赛 >
- 【HDU5922 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 A】【水题】Minimum’s Revenge
- HDU 5929 Basic Data Structure(模拟,deque)——2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- HDU 5922 Minimum’s Revenge 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
- HDU 5924 Mr. Frog’s Problem(想看证明的来)——2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- HDU 5922 Minimum’s Revenge 【模拟】(2016CCPC东北地区大学生程序设计竞赛)
- HDU 5926 Mr. Frog’s Game(连连看,暴力)——2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 部分题解
- 2016CCPC东北地区大学生程序设计竞赛1008/HDU 5929 模拟
- HDU Mr. Frog’s Problem 2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- (HDU 5924)Mr. Frog’s Problem 思维水题 <2016CCPC东北地区大学生程序设计竞赛 - 重现赛 >
- (HDU 5926)Mr. Frog’s Game 水题 <2016CCPC东北地区大学生程序设计竞赛 - 重现赛 >
- hdu5922 2016CCPC东北地区大学生程序设计竞赛 A题 Minimum’s Revenge(思维,水题)
- (HDU 5927)Auxiliary Set 思维题 <2016CCPC东北地区大学生程序设计竞赛 - 重现赛 >
- hdu 5927 Auxiliary Set 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 F题(树状dp)
- 2016CCPC东北地区大学生程序设计竞赛-Minimum’s Revenge
- HDU Mr. Frog’s Game 2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- (HDU 5929)Basic Data Structure 双端队列+模拟 <2016CCPC东北地区大学生程序设计竞赛 - 重现赛 >
- HDU Basic Data Structure 2016CCPC东北地区大学生程序设计竞赛 - 重现赛