C. Maximal GCD
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a2, ..., ak, that their sum is equal to n and greatest common divisor is maximal.

Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by them.

If there is no possible sequence then output -1.

Input

The first line consists of two numbers n and k (1 ≤ n, k ≤ 1010).

Output

If the answer exists then output k numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them.

Examples
input
6 3
output
1 2 3
input
8 2
output
2 6
input
5 3
output
-1
暴力枚举,k个数都是n的因子
 n - s > (k - 1)·d.然后从d枚举到n/d就好了,这个思路我是想不到的,听打神讲的,然而我还写不出来,抄了大神的代码,CF这样很好啊。帮助小白进阶,从哪里开始枚举
自己要想清楚
#include <cstdio>
typedef long long ll;
int main()
{
ll n, k;
scanf("%lld%lld", &n, &k);
if (k > (ll)1e8)
{
printf("-1\n");
return ;
}
ll b = n / (k * (k + ) / );
if (b == )
{
printf("-1\n");
return ;
}
ll r = ;
for (ll x = ; x * x <= n; x++)
{
if (n % x != ) continue;
if (x <= b && x > r) r = x;
if (n / x <= b && n / x > r) r = n / x;
}
for (int i = ; i < k; i++)
printf("%lld ", r * i);
n -= r * k * (k - ) / ;
printf("%lld\n", n); return ;
}

Educational Codeforces Round 20 C. Maximal GCD的更多相关文章

  1. Educational Codeforces Round 20 A. Maximal Binary Matrix

    A. Maximal Binary Matrix time limit per test 1 second memory limit per test 256 megabytes input stan ...

  2. Educational Codeforces Round 20

    Educational Codeforces Round 20  A. Maximal Binary Matrix 直接从上到下从左到右填,注意只剩一个要填的位置的情况 view code //#pr ...

  3. Educational Codeforces Round 20.C

    C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. Educational Codeforces Round 20 C 数学/贪心/构造

    C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  5. Educational Codeforces Round 20 D. Magazine Ad

    The main city magazine offers its readers an opportunity to publish their ads. The format of the ad ...

  6. Educational Codeforces Round 20 C(math)

    題目鏈接: http://codeforces.com/problemset/problem/803/C 題意: 給出兩個數n, k, 將n拆分成k個數的和,要求這k個數是嚴格遞增的,並且這k個數的g ...

  7. Educational Codeforces Round 20 A

    Description You are given matrix with n rows and n columns filled with zeroes. You should put k ones ...

  8. Educational Codeforces Round 20 B. Distances to Zero

    B. Distances to Zero time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  9. Educational Codeforces Round 20 E - Roma and Poker(dp)

    传送门 题意 Roma在玩一个游戏,一共玩了n局,赢则bourle+1,输则bourle-1,Roma将会在以下情况中退出 1.他赢了k个bourle 2.他输了k个bourle 现在给出一个字符串 ...

随机推荐

  1. npm使用快速的安装源(nrm)

    安装 npm install nrm --global 使用 nrm ls 切换安装源 nrm use taobao 测速 nrm test npm 参考地址:http://codingdict.co ...

  2. HTTP错误码汇总(转)

    响应码由三位十进制数字组成,它们出现在由HTTP服务器发送的响应的第一行.响应码分五种类型,由它们的第一位数字表示:1.1xx:信息,请求收到,继续处理2.2xx:成功,行为被成功地接受.理解和采纳3 ...

  3. 【Python图像特征的音乐序列生成】关于数据库到底在哪里下载

    毕竟原网站一个是14年前的一个是16年前的…… 1,http://ifdo.ca/~seymour/nottingham/nottingham.html 这个网站可以下载zip包. 2,https:/ ...

  4. 2017年团体程序设计天梯赛 - 大区赛 L3-3

    题意:有向图找哈密顿回路 比赛的时候剪枝只剪了vis 状压没剪对 反而只拿17分... 比赛结束后还去看了一发这个NP问题的QB(快速回溯法...但是对于本题好像大材小用...) 上网看了一个神犇的写 ...

  5. Android(java)学习笔记123:Android MediaPlayer 播放prepareAsync called in state 8解决办法

    1. 使用android MediaPlayer播放音频文件时,有时会出现prepareasync called in state 8错误. 以下方法可以避免这个异常出现.  第1种方法: priva ...

  6. tpcc-mysql 实践

    一.TPCC 介绍 TPC:全称Transaction Processing Performance Council (事务处理性能委员会),是一家非盈利性组织,该组织制定各种商业应用的基准测试规范, ...

  7. Python-OpenCV——Image Blurring(Image Smoothing)

    通过将图像与低通滤波器内核卷积来实现图像模糊.它有助于消除噪音.它实际上从图像中去除了高频内容(例如:噪声,边缘).因此在此操作中边缘会有点模(嗯,有模糊技术,也不会模糊边缘). OpenCV主要提供 ...

  8. Fruit Ninja(取随机数)

    链接:https://www.nowcoder.com/acm/contest/163/A来源:牛客网 时间限制:C/C++ 5秒,其他语言10秒 空间限制:C/C++ 262144K,其他语言524 ...

  9. 11.使用while和for循环分别打印字符串s=’asdfer’中每个元素

    1).for循环 s = 'asdfer' for i in s: print(i) 2).while循环 s = 'asdfer' while 1: print(s[index]) index += ...

  10. Bootstrap历练实例:带链接的警告

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...