Question:题目详情(http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1001&cid=729)
题目大意:给你1~n,任意两点的权值为他们的乘积,问连接说有的点最小需要的权值和为多少
解题思路:这道题有点最小生成树的感觉,但数据太大,所以找其他方法,起始仔细观察,任意一点都与1相连权值是最小的
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
int main()
{
int T,ncase=0;
LL n;
cin>>T;
while(T--)
{
LL sum=0;
cin>>n;
sum=(1+n)*n/2-1; //用1~n的等差数列和减去1即可
printf("Case #%d: %lld\n",++ncase,sum);
}
return 0;
}
体会:这是一道简单题,但要注意取值范围