题干:
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≤100T≤100), which indicates the number of test cases.
For each test case, the first line contains only one integer n (2≤n≤1092≤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.
题目大意:
给一个n个点的图,编号1~n,每两个点u,v之间都有连边,边权=lcm(u,v),求最小生成树的权值和。
解题报告:
一眼扫过去是,所有点都和1号点连边。简单证明一下:别对lcm进行公式的化简,既然每个点的编号都要至少被考虑一次(连边一条),考虑每个点的编号x对答案的影响,这个点不论和谁连边,那LCM肯定>=x,且另一个点取x的因子时可以取等,1是所有数的因子,所以和1连边,所以每个点都可以取等,所以都和1连边肯定是最小的。等差公式求个和就行了。
AC代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
int a[MAX],b[MAX],n;
int main()
{int T,iCase=0;cin>>T;while(T--) {cin>>n;printf("Case #%d: %lld\n",++iCase,1LL*n*(n+1)/2-1);}return 0 ;
}