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. MVC三层架构的分层开发思想

  2. 简述对Vuex的理解

          1.什么是Vuex:             Vuex是一个专为Vue.js应用程序开发的状态管理模式.     2.使用Vuex的原因:             当我们遇到多个组件共享状 ...

  3. 1.Hadoop集群安装部署

    Hadoop集群安装部署 1.介绍 (1)架构模型 (2)使用工具 VMWARE cenos7 Xshell Xftp jdk-8u91-linux-x64.rpm hadoop-2.7.3.tar. ...

  4. 树莓派3B+学习笔记:9、更改软件源

    树莓派系统安装完成后,由于默认软件源服务器访问速度慢,安装软件耗时会很长,可以通过更改软件源来加快软件的安装速度. 系统安装完成后默认软件源如下: 更改镜像源前需要自行查找镜像源,并记下网址: 1.阿 ...

  5. Navicat 报错1251连接不成功Mysql

    使用Navicat 连接数据库时候出现1251错误,解决方法. 1.首先打开mysql.exe,然后输入密码(mysql.exe可以在安装的位置搜索一下) 2.输入ALTER USER 'root'@ ...

  6. 关于typedef在struct使用上的一些问题

    typedef struct lnode{ int data; struct lnode next; }lnode,linklist; 第一行的lnode是结构体名,最后一行的lnode是由typed ...

  7. poj 2349 Arctic Network(prime)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25165   Accepted: 7751 Description The ...

  8. Tokio,Rust异步编程实践之路

    缘起 在许多编程语言里,我们都非常乐于去研究在这个语言中所使用的异步网络编程的框架,比如说Python的 Gevent.asyncio,Nginx 和 OpenResty,Go 等,今年年初我开始接触 ...

  9. 20155320 2016-2017-2《Java程序设计》课程总结

    20155320 2016-2017-2<Java程序设计>课程总结 (按顺序)每周作业链接汇总 预备作业1:第一次写随笔,回答了老师的一些问题,写下了期望和目标 预备作业2:总结了一下自 ...

  10. [arc065E]Manhattan Compass[曼哈顿距离和切比雪夫距离转换]

    Description 传送门 Solution 题目要求的是曼达顿距离,对于每个点(x,y),我们把它变为(x-y,x+y),就可以转换成求切比雪夫距离了. 证明如下:$max(\left | (x ...