HDU 5922 Minimum’s Revenge 模拟 (2016CCPC东北地区大学生程序设计竞赛)
Posted Coolxxx
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 5922 Minimum’s Revenge 模拟 (2016CCPC东北地区大学生程序设计竞赛)相关的知识,希望对你有一定的参考价值。
Minimum’s Revenge
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 283 Accepted Submission(s): 219Problem DescriptionThere 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 multipleof their indexes.
Mr. Frog is wondering about the total weight of the minimum spanning tree. Can you help him?
InputThe 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.
OutputFor 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 Input2 2 3
Sample OutputCase #1: 2 Case #2: 5HintIn 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.
Source
Recommend
Statistic | Submit | Discuss | Note
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5922
题目大意:
N个点1~N(N<=109),x与y之间的边的权为x与y的最小公倍数,求最小生成树的边权和。
题目思路:
【模拟】【构造】
这样构造数:质数与1相连,其余与任意一个因子相连,这样边权最小,所以当N=2时答案为2,否则为2+3+...+N。
1 // 2 //by coolxxx 3 //#include<bits/stdc++.h> 4 #include<iostream> 5 #include<algorithm> 6 #include<string> 7 #include<iomanip> 8 #include<map> 9 #include<stack> 10 #include<queue> 11 #include<set> 12 #include<bitset> 13 #include<memory.h> 14 #include<time.h> 15 #include<stdio.h> 16 #include<stdlib.h> 17 #include<string.h> 18 //#include<stdbool.h> 19 #include<math.h> 20 #pragma comment(linker,"/STACK:1024000000,1024000000") 21 #define min(a,b) ((a)<(b)?(a):(b)) 22 #define max(a,b) ((a)>(b)?(a):(b)) 23 #define abs(a) ((a)>0?(a):(-(a))) 24 #define lowbit(a) (a&(-a)) 25 #define sqr(a) ((a)*(a)) 26 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b)) 27 #define mem(a,b) memset(a,b,sizeof(a)) 28 #define eps (1e-10) 29 #define J 10000 30 #define mod 1000000007 31 #define MAX 0x7f7f7f7f 32 #define PI 3.14159265358979323 33 #define N 100004 34 using namespace std; 35 typedef long long LL; 36 double anss; 37 LL aans; 38 int cas,cass; 39 LL n,m,lll,ans; 40 41 int main() 42 { 43 #ifndef ONLINE_JUDGEW 44 // freopen("1.txt","r",stdin); 45 // freopen("2.txt","w",stdout); 46 #endif 47 int i,j,k; 48 int x,y,z; 49 // init(); 50 // for(scanf("%d",&cass);cass;cass--) 51 for(scanf("%d",&cas),cass=1;cass<=cas;cass++) 52 // while(~scanf("%s",s)) 53 // while(~scanf("%d%d",&n,&m)) 54 { 55 printf("Case #%d: ",cass); 56 scanf("%lld",&n); 57 if(n==2)puts("2"); 58 else printf("%lld\\n",n*(n+1)/2-1); 59 } 60 return 0; 61 } 62 /* 63 // 64 65 // 66 */
Minimum’s Revenge
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 283 Accepted Submission(s): 219
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≤109), indicating the number of vertices.
以上是关于HDU 5922 Minimum’s Revenge 模拟 (2016CCPC东北地区大学生程序设计竞赛)的主要内容,如果未能解决你的问题,请参考以下文章
HDU 1394 Minimum Inversion Number
hdu 1394 Minimum Inversion Number
[hdu1394]Minimum Inversion Number(树状数组)
hdu1394 Minimum Inversion Number(最小逆序数)