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
1
5 3
Output
1 2 2
Note

The strictly positive integers are the set defined as: . That is, all the integers that are strictly greater than zero: .

题目意思:对于T组输入输出,给你一个n将其分为k份,要求分成的份最大值和最小值相差最小。

解题思路:这道题很简单,我看了队友写的代码后发现这个题还挺有意思的,这里给出解释。

例如10分成4份,用10直接去整除4得到的是2,我们可以这样理解平均每一份是ans 2,即n/k得到的是一种平均的分配,但是这样还没有全部分完n,还会有余数m=n%k,因为m必然是比k小的数,也就可以理解为有m个分数需要在原来的ans上再加一个上1,这样得到的分配能够保证最大值和最小值相差最小。

 #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-ans*k;
for(i=;i<k-m;i++)
{
printf("%d ",ans);
}
for(i=k-m;i<k;i++)
{ if(i==k-)
{
printf("%d\n",ans+);
}
else
{
printf("%d ",ans+);
}
}
}
return ;
}

Split the Number(思维)的更多相关文章

  1. Codeforces C. Split a Number(贪心大数运算)

    题目描述: time limit per test 2 seconds memory limit per test 512 megabytes input standard input output ...

  2. Codeforces Round #567 (Div. 2)B. Split a Number (字符串,贪心)

    B. Split a Number time limit per test2 seconds memory limit per test512 megabytes inputstandard inpu ...

  3. B. Split a Number(字符串加法)

    Dima worked all day and wrote down on a long paper strip his favorite number nn consisting of ll dig ...

  4. Codeforces Round #567 (Div. 2) B. Split a Number

    Split a Number time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...

  5. Codeforces - 1181B - Split a Number - 贪心

    https://codeforces.com/contest/1181/problem/B 从中间拆开然后用大数搞一波. 当时没想清楚奇偶是怎么弄,其实都可以,奇数长度字符串的中心就在len/2,偶数 ...

  6. 2019牛客多校训练第四场K.number(思维)

    题目传送门 题意: 输入一个只包含数字的字符串,求出是300的倍数的子串的个数(不同位置的0.00.000等都算,并考虑前导零的情况). sample input: 600 1230003210132 ...

  7. ZOJ - 2132:The Most Frequent Number(思维题)

    pro:给定N个数的数组a[],其中一个数X的出现次数大于N/2,求X,空间很小. sol:不能用保存数组,考虑其他做法. 由于出现次数较多,我们维护一个栈,栈中的数字相同,所以我们记录栈的元素和个数 ...

  8. index.js:13 Uncaught TypeError: Cannot read property 'split' of undefined

    使用 webpack 编译 Vue 项目时出现报错: index.js:13 Uncaught TypeError: Cannot read property 'split' of undefined ...

  9. split 过滤空的元素

    命令形式: split(str='',number=string.count(str))[n] str 分隔符 number 切分几次,[n] 获取第几个值. 1.如果切分的可迭代对象中包含空元素的解 ...

随机推荐

  1. LR--用栈实现移进--归约分析(demo)

    1.考虑文法 \(E->E+E\) \(E->E*E\) \(E->id\) 2.最右推导 不难看出,这个文法是而二义的,所以有多个最右推导 3.移进归约 用一个栈存文法符号,用输入 ...

  2. es6 入坑笔记(二)---函数扩展,箭头函数,扩展运算符...

    函数扩展 1.函数可以有默认值 function demo( a = 10,b ){} 2.函数可以使用解构 function demo( { a = 0,b = 0 } = {} ){ } 3.函数 ...

  3. Cloudera环境搭建

    在开发阶段,可以单机搭建环境安装Flume和Solr,在两个工程的官网下载相关文件. 还有另一种更便捷的方式,就是使用Cloudera提供的镜像,包括了已经配置好的各种大数据服务环境的docker镜像 ...

  4. python最新笔试题

    这是笔者面试小十家公司后呕心沥血总结的一些笔试编程题~具体公司就不透露了.哎,说多了都是泪啊. 1.二分法查找: l = [1, 2, 3, 4, 5, 6, 7, 8, 9] find_num = ...

  5. PHP 审计

    1.get  和post  上传数组,数组的sha1值相等 通过阅读代码,我们发现要想得到flag就要达到下面三个条件: 使 uname的sha1值 与 passwd的sha1的值 相等    但是同 ...

  6. Python3的venv虚拟环境操作(Linux)

    Infi-chu: http://www.cnblogs.com/Infi-chu/ Python3.3以上版本支持了原生的虚拟环境命令,即venv. 长话短说,具体的理论在这里就不多说了,主要的操作 ...

  7. Go类型特性-学习笔记

    1.组合 Go语言使用组合来完成类型的设计,设计某一类型时想要拥有其他类型的功能只需要将其他类型嵌入该类型即可. 2.接口 与其他语言不同的是,编译器会自动判断该类型是否符合某正在使用的接口,甚至不需 ...

  8. 20155204 2016-2017-2 《Java程序设计》第4周学习总结

    20155204 2016-2017-2 <Java程序设计>第4周学习总结 教材学习内容总结 继承是类与类之间的联系,接口是方法与类之间的联系,多态就是指利用接口和继承来派生许多类. 有 ...

  9. 20155207JAVA第十二周课堂练习

    20155207JAVA第十二周课堂练习 教材代码检查--P98 修改教材P98 Score2.java, 让执行结果数组填充是自己的学号 Arrays和String单元测试 在IDEA中以TDD的方 ...

  10. 238. Product of Array Except Self(对O(n)和递归又有了新的理解)

    238. Product of Array Except Self     Total Accepted: 41565 Total Submissions: 97898 Difficulty: Med ...