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.
题目分析
题目大意:建图,求图最小边权和:边权为两点序号的 L C M LCM LCM。
我们很容易想到:使每条边权最小的时候,应该将所有的点与1点相连,使得所有边权最小化。
因此图的结构被确定了,每条边的边权也唯一固定: 2 , 3 , 4 … n 2,3,4…n 2,3,4…n。可以推出以下公式: n ∗ ( n + 1 ) / 2 − 1 n * (n + 1) / 2 - 1 n∗(n+1)/2−1
AC Code#include
#define ll long long
using namespace std;
int main(){
int t = 0, cas = 0; cin >> t;
while(t--){
ll ans = 0, n = 0; cin >> n;
ans = (n + 2) * (n - 1) / 2;
cout
关注
打赏
- 回坑记之或许是退役赛季?
- [LCT刷题] P1501 [国家集训队]Tree II
- [LCT刷题] P2147 洞穴勘测
- 2022-2023 ICPC Brazil Subregional Programming Contest VP记录
- [线段树套单调栈] 2019-2020 ICPC Asia Hong Kong Regional Contest H.[Hold the Line]
- The 2021 ICPC Asia Nanjing Regional Contest E.Paimon Segment Tree 区间合并线段树/维护矩阵乘法
- CF580E - Kefa and Watch 线段树维护哈希
- HDU5869 Different GCD Subarray Query 离线查询/区间贡献
- 27.CF1004F Sonya and Bitwise OR 区间合并线段树
- 26.CF1000F One Occurrence