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-verify.js

    废话不说,直接上代码说明,1分钟学会: 例: 1.验证配置 $.extend(Verify.types, { "must" : { "verify" : fun ...

  2. 浅谈spj

    SPJ(special judge)是个好玩的东西,毕竟各类神奇的题目SPJ经常作为救火工具(比如说一不小心出成验证类的题目). 但SPJ是个坑,毕竟只让用个“testlib.h”,输入还特别奇怪.今 ...

  3. code#5 P4 逻辑树

    逻辑树   时间限制: 3.0 秒 空间限制: 512 MB 相关文件: 题目目录 题目描述 有一棵树,叫逻辑树. 这个树有根,有 2N−1 个节点,其中 N 个叶子,每个非叶节点恰好有两个孩子. 每 ...

  4. VUE 采坑之旅-- Mint-ui 按需引入报出Module build failed: Error: Couldn't find preset "es2015" relative to directory "C:\\phpStudy\\PHPTutorial\\WWW\\text\\vuep\\vue-demo"

    首先按照mint-ui的文档中按需引入的要求,先执行 npm install babel-plugin-component -D 然后,将.babelrc文件替换了,但是后来我又将其改了(采坑过程我也 ...

  5. C# 操作word 模板 值 替换

    1.引用 aspose.words   dll 2.word 使用doc 3.给word 模板中添加要替换位置的 书签 .引用 aspose.words dll .word 使用doc .给word ...

  6. Redis数据库 : 基础

    设置密码: /etc/redis/redis.conf 文件把 requirepass 取消注释并设置密码 取消只能本地登录的bind 同上面的配置文件 把 bind一行注释掉 带密码登录: redi ...

  7. laravel5.5源码笔记(三、门面类facade)

    上次说了provider,那么这次来说说facade 首先是启动的源头,从laravel的kernel类中的$bootstrappers 数组,我们可以看到它的一些系统引导方法,其中的Register ...

  8. 【 C 】字符串常量

    当一个字符串常量出现在表达式中时,它的值是个指针常量.编译器把这些指定字符的一份拷贝存储在内存的某个位置,并存储一个指向第一个字符的指针.但是,当数组名用于表达式中时,它们的值也是个指针常量.我们可以 ...

  9. makefile中重载与取消隐藏规则示例

    学习<跟我一起写Makefile-陈皓>后一直不懂,如何重载或取消隐藏规则 为了博客版面整洁,何为隐藏规则,Makefile基本规则编写等基础支持请自行百度. 需要声明的是:这些知识可能在 ...

  10. 再装虚拟机及git

    再装虚拟机及git 问题1:在假期的学习中并没有上传代码的习惯,到了开学要用到的时候发现新建的目录无法git到码云上,当时也没有在意,直到老师问我要代码链接才意识到这个问题. 问题2:在按照老师的博客 ...