Time Limit: 1000MS | Memory Limit: 65536KB | 64bit IO Format: %I64d & %I64u |
Description
Boxing, karate, sambo… The audience is sick of classic combat sports. That is why a popular sports channel launches a new competition format based on the traditional Russian entertainment called line fighting. There can be from 2 to
k
teams taking part in a competition, and there are
n
fighters altogether in all the teams. Before the competition starts, the fighters are divided into teams: each fighter becomes a member of exactly one team. Two fighters fight each other if they are members of different teams. The organizers believe that the more the number of fights between fighters, the higher the popularity of a competition will be. Help the organizers to distribute fighters between teams so as to maximize the number of fights and output this number.
Input
The first line contains the number of tests
T
(1 ≤
T
≤ 10). In each of the following
T
lines you are given a test: integers
n
and
k
separated with a space (2 ≤
k
≤
n
≤ 10
4).
Output
For each test output the answer (one integer) in a separate line.
Sample Input
input | output |
---|---|
3 6 3 5 5 4 2 | 12 10 4 |
n人分为k组对决,同组不对决,求最多能有几次对决。
k组人数尽量平均,各组间对决次数为各自人数的乘积,枚举累计就好了。
#include<iostream>
using namespace std;
const int MAXN=10010;
long long int t[MAXN];
int main()
{
long long int n,k;
int casen;
cin>>casen;
while(casen--)
{
cin>>n>>k;
long long int num=n/k;
for(int i=0;i<k;i++)
t[i]=num;
long long int yu=n%k;
long long int i=0;
while(yu--)
t[i++]++;
int sum=0;
for(int i=0;i<k;i++)
for(int j=i+1;j<k;j++)
sum=sum+t[i]*t[j];
cout<<sum<<endl;
}
}