Friends and Cookies(第二次组队赛)

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:

  1. Give a cookie to the 1st friend.
  2. Give a cookie to the 2nd friend.
  3. Give a cookie to the 3rd friend.
  4. Give a cookie to the 4th friend.
  5. Give a cookie to the 3rd friend.
  6. Give a cookie to the 2nd friend.
  7. Give a cookie to the 1st friend.
  8. Give a cookie to the 2nd friend.
  9. 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 ithfriend got.

Example

input

1
5 3

output

2 2 1

这道题不是我做的,从始至终没有好好的看我队友的代码,很后悔。赛后发现只考虑差一种情况。

题意:循环分x个东西给n个人,只要找到规律就好啦。注意特判一下只有一个人的情况。

ac代码:

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    int k;
    long long x,n,a,b,i,j,t[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)
                t[i]=a;
            else if(i==n)
                t[i]=a;
            else
                t[i]=2*a;
        }
        if(b<=n)
        {
            for(i=1; i<=b; i++)
            {
                t[i]++;
            }
        }
        else
        {
            for(i=1; i<=n; i++)
                t[i]++;
            i--;
            for(j=n+1; j<=b; j++)
                t[--i]++;
        }
        for(i=1; i<=n; i++)
        {
            if(i!=n)
                printf("%lld ",t[i]);
            else
                printf("%lld\n",t[i]);
        }

    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值