您当前的位置: 首页 > 

HeartFireY

暂无认证

  • 0浏览

    0关注

    334博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Minimum’s Revenge

HeartFireY 发布时间:2021-02-13 11:50:52 ,浏览量: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.
题目分析

题目大意:建图,求图最小边权和:边权为两点序号的 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             
关注
打赏
1662600635
查看更多评论
0.0374s