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

Copy

1
5 3

output

Copy

2 2 1

题解:分配蛋糕,特判一下n==1和n==2的情况和n<=k,然后其他情况就是一种规律。

代码如下:

#include <map>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define fori(a) for(ll i=0;i<a;i++)
#define forj(a) for(ll j=0;j<a;j++)
#define ifor(a) for(ll i=1;i<=a;i++)
#define jfor(a) for(ll j=1;j<=a;j++)
#define mem(a,b) memset(a,b,sizeof(a))
#define iFor(a,b,d) for(ll i=a;i<b;i+=d)
using namespace std;
typedef long long ll;
const ll maxn =  1e3+10;
const ll INF = 0x3f3f3f3f;
const ll inf = 0x3f;
const double EPS = 1e-7;
const double Pi = acos(-1);
const ll MOD = 1e9+7;
ll a[maxn];
int  main()
{
    ll t,n,k;
    cin >> t ;
    while(t--)
    {
        mem(a,0);
        cin>>n>>k;
        if( n<= k)
        {
            ifor(n)
            a[i] = 1;
            ifor(k)
            cout << a[i] <<" ";
            cout << endl;
        }
        else if (k == 1)
            cout << n << endl;
        else if(k == 2)
        {
            cout << n/2+n%2<<" "<<n/2 <<endl;
        }
        else
        {
            ll l=0,sum=2*(k-2)+2;
            ll temp=-1,flag=0;
            while(n)
            {
                if(n>=sum)
                {
                    l=n/sum;
                    n%=sum;
                }
                else
                {
                    if(n>k)
                    {
                        n-=k;
                        flag=1;
                        temp=n;
                        n=0;
                    }
                    else
                    {
                        temp=n;
                        n=0;
                    }
                }
            }
            for(ll i=0; i<k; i++)
            {
                if(i==0||i==k-1)
                    a[i]=l;
                else
                    a[i]=l*2;
            }
            if(flag==1&&temp!=-1)
            {
                for(ll i=0; i<k; i++)
                {
                    a[i]++;
                }
                for(ll i=k-2;i>k-2-temp;i--)
                    a[i]++;
            }
            if(flag==0&&temp!=-1)
            {
                for(ll i=0; i<temp; i++)
                {
                    a[i]++;
                }
            }
            for(ll i=0; i<k; i++)
            {
                printf("%I64d",a[i]);
                if(i!=k-1)
                    printf(" ");
                else
                    printf("\n");
            }
        }
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值