日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

【HDU - 5922】Minimum’s Revenge(思维,最小生成树变形)

發(fā)布時間:2023/12/10 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 5922】Minimum’s Revenge(思维,最小生成树变形) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題干:

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是所有數(shù)的因子,所以和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 ; }

?

總結

以上是生活随笔為你收集整理的【HDU - 5922】Minimum’s Revenge(思维,最小生成树变形)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。