A - Minimum’s Revenge
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?
Mr. Frog is wondering about the total weight of the minimum spanning tree. Can you help him?
For each test case, the first line contains only one integer n (2≤n≤1092≤n≤109), indicating the number of vertices.
2 2 3
Case #1: 2
Case #2: 5
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.
AC代码:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++)
{
long long n;
cin>>n;
long long ans;
ans=(n+2)*(n-1)/2;
printf("Case #%d: ",i);
cout<<ans<<endl;
}
return 0;
}
#include<algorithm>
#include<cstring>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++)
{
long long n;
cin>>n;
long long ans;
ans=(n+2)*(n-1)/2;
printf("Case #%d: ",i);
cout<<ans<<endl;
}
return 0;
}