2016CCPC东北地区大学生程序设计竞赛-Minimum’s Revenge
2016-10-06 15:15
459 查看
Minimum’s Revenge
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
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 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
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.
解题思路:最小公倍数大于或等于两数中的任何一个。所以让2~n跟1相连就是最小生成树权值总和2+3+4+……+n开始差点想用Prim和gcd,too young too naive!
#include<iostream> #include<cstdio> using namespace std; typedef long long LL; int main() { ios::sync_with_stdio(false); cin.tie(0); int T; cin>>T; LL n; for(int i=1;i<=T;i++) { cin>>n; cout<<"Case #"<<i<<": "<<(n+2)*(n-1)/2<<endl; } return 0; }
相关文章推荐
- (HDU 5922)Minimum’s Revenge 思维水题 <2016CCPC东北地区大学生程序设计竞赛 - 重现赛 >
- 【HDU5922 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 A】【水题】Minimum’s Revenge
- hdu5922 2016CCPC东北地区大学生程序设计竞赛 A题 Minimum’s Revenge(思维,水题)
- HDU 5922 Minimum’s Revenge 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
- HDU 5922 Minimum’s Revenge 【模拟】(2016CCPC东北地区大学生程序设计竞赛)
- 2016CCPC东北地区大学生程序设计竞赛【01/03/05/06/08】
- [2016CCPC东北地区大学生程序设计竞赛]Mr. Frog’s Problem 规律+打表
- 【HDU5929 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 H】【打表找规律 队列模拟】Basic Data Structure 双端栈下连续1和0做nand的结果
- HDU Mr. Frog’s Game 2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- 【HDU5931 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 J】【线性规划 乱搞】Mission Possible 购买护甲和回复力和速度使得最小成本穿越D距离
- HDU Basic Data Structure 2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- 【HDU5932 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 K】【树上背包 贪心乱搞】Backpack on Tree 物品成本只有12345下的树上背包
- HDU 5922 Minimum’s Revenge(思维题)——2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- hdu 5926 Mr. Frog’s Game 2016CCPC东北地区大学生程序设计竞赛E题(模拟)
- HDU 5929 Basic Data Structure 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
- 2016CCPC东北地区大学生程序设计竞赛 - Auxiliary Set(思维题)
- 2016CCPC东北地区大学生程序设计竞赛 1003 HDU5924
- HDU 5927 Auxiliary Set 【DFS+树】(2016CCPC东北地区大学生程序设计竞赛)
- HDU 5929 Basic Data Structure 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
- hdu 5927 Auxiliary Set 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 F题(树状dp)