hdu 6090
思路:菊花状的图。。。注意边大于构成完全图的情况
1 #include<bits/stdc++.h> 2 typedef long long ll; 3 using namespace std; 4 5 int main(){ 6 int t; 7 scanf("%d",&t); 8 while(t--){ 9 ll n,m; 10 scanf("%lld%lld",&n,&m); 11 ll sum=0; 12 if(m>=n-1){ 13 sum+=n-1; 14 sum+=(n-1)*(1+(n-2)*2); 15 m-=n-1; 16 if(m>0){ 17 sum-=min(m,n-1)*2; 18 m-=n-1; 19 } 20 for(ll i=n-3;i>=1;i--){ 21 if(m<=0) break; 22 sum-=min(m,i)*2; 23 m-=i; 24 } 25 sum=max(sum,n*(n-1)); 26 } 27 else { 28 ll x=n-(m+1); 29 sum+=m; 30 sum+=m*(1+(m-1)*2); 31 sum+=2*x*(m+1)*n; 32 sum+=(n-m-1)*(n-m-2)*n; 33 } 34 printf("%lld\n",sum); 35 } 36 }