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 kteams taking part in a competition, and there aren 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.
Example
input | output |
---|---|
3 6 3 5 5 4 2 | 12 10 4 |
AC代码(就是把他们分组分的组数越多越好分的越均衡越好然后就像打电话问题一样同组内的人是不需要挑战的)
Select Code
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main()
{
int t, a[10000+10], b[10000+10], i, n, k, sm;
scanf("%d",&t);
while(t--)
{
sm = 0;
scanf("%d %d",&n,&k);
int x = n%k;
for(i = 0;i<k;i++)
{
a[i] = n/k;
}
for(i = 0;i<x;i++)
{
a[i]++;
}
b[k-1] = a[k-1];
for(i = k-2;i>=0;i--)
{
b[i] = a[i]+b[i+1];
}
for(i = 0;i<k-1;i++)
{
sm+=a[i]*b[i+1];
}
printf("%d\n",sm);
}
return 0;
}