I. Split the Number
time limit per test
1.0 s
memory limit per test
256 MB
input
standard input
output
standard output
You are given an integer x. Your task is to split the number x into exactly n strictly positive integers such that the difference between the largest and smallest integer among them is as minimal as possible. 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 ≤ 109, 1 ≤ n ≤ 1000), as described in the statement above.
Output
For each test case, print a single line containing n space-separated integers sorted in a non-decreasing order. If there is no answer, print - 1.
Example
input
Copy
1 5 3
output
Copy
1 2 2
Note
The strictly positive integers are the set defined as: . That is, all the integers that are strictly greater than zero: .
除与余是关键运算
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int t,ans,m,i,k,n;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&k);
if(n<k)
{
printf("-1\n");
continue;
}
ans=n/k;
m=n%k;
for(i=1;i<=k-m;i++)
{
printf("%d ",ans);
}
for(i=k-m+1;i<=k;i++)
{
if(i==k)
printf("%d\n",ans+1);
else
printf("%d ",ans+1);
}
}
return 0;
}