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
题意:按照下图所示顺序:将一块给第一个人,再将一块给第二个人,直至将所有的蛋糕分完
找规律+讨论
第一排每人一块蛋糕,之后每一排n-1块蛋糕
(除第一排)剩奇数排 第一位比最后一位多分一块
剩偶数排,第一位和最后一排分的一样多,都为剩下的排数的一半
所以有以下解法:
x块蛋糕n个人
if(n==1)
直接输出x(从后面的讨论中区分出来,不区分的话 后面无法处理)
else
if(x<n)
输出x个1,n-x个0 (注意:printf(“%d”,1); 此处的1为int型,想要输出long long int,要将常数1转成long long int型)
else
每排加1,之后将每一排分三分,第一个 最后一个 以及 中间的人
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <vector>
#include <numeric>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define eps 1e-8
#define PI acos(-1)
#define INF 0x3f3f3f3f
using namespace std;
const int N=1000 + 10 ;
typedef long long LL;
const int dir[4][2]= { {1,0},{0,1},{-1,0},{0,-1} };
int GCD(int a,int b)
{
return b ? GCD(b,a%b) : a;
}
int main()
{
int T;
cin>>T;
while(T--)
{
LL i,x,n,a,b;
LL ans[N];
memset(ans,0,sizeof(ans));
scanf("%lld%lld",&x,&n);
if(n!=1)
{
if(x>=n)
{
x-=n;
for(i=0; i<n; i++)
{
ans[i]=1;
}
a=x/(n-1);
b=x%(n-1);
if(a%2==0)
{
ans[0]+=a/2;
ans[n-1]+=a/2;
for(i=0; i<b; i++)
ans[n-i-1-1]++;
}
else
{
ans[0]+=a/2;
ans[n-1]+=a/2;
ans[0]++;
for(i=0; i<b; i++)
ans[1+i]++;
}
for(i=1; i<n-1; i++)
ans[i]+=a;
for(i=0; i<n; i++)
printf("%lld%c",ans[i],i==n-1?'\n':' ');
}
else
{
for(i=0;i<n;i++)
{
if(i<x)
printf("%lld%c",(LL)1,i==n-1?'\n':' ');
else
printf("%lld%c",(LL)0,i==n-1?'\n':' ');
}
}
}
else
printf("%lld\n",x);
}
return 0;
}