Minimum spanning tree

Problem Description

Given n-1 points, numbered from 2 to n, the edge weight between the two points a and b is lcm(a, b). Please find the minimum spanning tree formed by them.

A minimum spanning tree is a subset of the edges of a connected, edge-weighted undirected graph that connects all the vertices together, without any cycles and with the minimum possible total edge weight. That is, it is a spanning tree whose sum of edge weights is as small as possible.

lcm(a, b) is the smallest positive integer that is divisible by both a and b.

Input

The first line contains a single integer t (t<=100) representing the number of test cases in the input. Then t test cases follow.

The only line of each test case contains one integers n (2<=n<=10000000) as mentioned above.

Output

For each test case, print one integer in one line, which is the minimum spanning tree edge weight sum.

Sample Input

2 2 6

Sample Output

0 26

代码如下

#include<iostream>
#define rep(i,x,y) for(auto i=(x);i<=(y);++i)
#define dep(i,x,y) for(auto i=(x);i>=(y);--i)
using namespace std;
typedef long long ll;
default_random_engine e;
int ui(int l,int r){
    uniform_int_distribution<int>u(l,r);
    return u(e);
}
ll ul(ll l,ll r){
    uniform_int_distribution<ll>u(l,r);
    return u(e);
}
double ud(double l,double r){
    uniform_real_distribution<double>u(l,r);
    return u(e);
}
const int N=2e6+10;
bool v[N];
int main(){
    e.seed(time(0));srand(time(0));
    freopen("in.txt","w",stdout);
    int t=100;
    printf("%d\n",t);
    rep(i,1,t){
        int n=ui(2,10000000);
        printf("%d\n",n);
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值