Abood’s birthday has come, and his n friends are aligned in a single line from 1 to n, waiting for their cookies, Abood has x cookies to give to his friends.
Here is an example to understand how Abood gives away the cookies. Suppose Abood has 4 friends and x cookies, then Abood will do the following:
Give a cookie to the 1st friend.
Give a cookie to the 2nd friend.
Give a cookie to the 3rd friend.
Give a cookie to the 4th friend.
Give a cookie to the 3rd friend.
Give a cookie to the 2nd friend.
Give a cookie to the 1st friend.
Give a cookie to the 2nd friend.
And so on until all the x cookies are given away.
Your task is to find how many cookies each friend will get. Can you?
Input
The first line contains an integer T (1 ≤ T ≤ 100) specifying the number of test cases.
Each test case consists of a single line containing two integers x and n (1 ≤ x ≤ 1018, 1 ≤ n ≤ 1000), in which x is the number of cookies Abood has, and n is the number of his friends.
Output
For each test case, print a single line containing n space-separated integers a1, …, an, in which ai represents how many cookies the ith friend got.
Example
Input
1
5 3
Output
2 2 1
题意:循环分x个东西给n个人,找规律。
注意特判一下只有一个人的情况。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int k;
ll x, n, a, b, i, j;
ll c[1005];
scanf("%d",&k);
while(k--)
{
scanf("%lld %lld",&x, &n);
if(n == 1)
{
printf("%lld\n",x);
continue;
}
a = x / (2 * n - 2);
b = x % (2 * n - 2);
for(i = 1; i <= n; i++)
{
if(i == 1)
c[i] = a;
else if(i == n)
c[i] = a;
else
c[i] = 2 * a;
}
if(b <= n)
{
for(i = 1; i <= b; i++)
{
c[i]++;
}
}
else
{
for(i = 1; i <= n; i++)
c[i]++;
i--;
for(j = n + 1; j <= b; j++)
c[--i]++;
}
for(i = 1; i <= n; i++)
{
if(i != n)
printf("%lld ",c[i]);
else
printf("%lld\n",c[i]);
}
}
return 0;
}