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. HTTP1.0工作原理

    1.HTTP工作原理 <HTTP响应报文与工作原理详解>讲的比较详细了. 2.示例 (1)server端程序如下: package org.yeyouluo.demo.jsp; impor ...

  2. iOS Automated Tests with UIAutomation

    参照:http://blog.manbolo.com/2012/04/08/ios-automated-tests-with-uiautomation#1 UI Automation JavaScri ...

  3. Typescript的优势

    TypeScript是一种由微软开发的自由开源的编程语言,他是JavaScript的一个超集,扩展了JavaScript的语法. 优势: 一.Angular2框架的开发语言 Angular2是一款开源 ...

  4. JS中的作用域和作用域链

    本文原链接:https://cloud.tencent.com/developer/article/1403589 前言 作用域(Scope) 1. 什么是作用域 2. 全局作用域和函数作用域 3. ...

  5. iOS深拷贝与浅拷贝

    概念 对象拷贝有两种方式:浅复制和深复制.顾名思义,浅复制,并不拷贝对象本身,仅仅是拷贝指向对象的指针:深复制是直接拷贝整个对象内存到另一块内存中. 如图详解:

  6. 如何在 JavaScript 中更好地使用数组

    使用 Array.includes 替代 Array.indexOf “如果需要在数组中查找某个元素,请使用 Array.indexOf.” 我记得在我学习 JavaScript 的课程中有类似的这么 ...

  7. C# WPF 粘贴板记录器

    工作学习中需要搜索很多资料,有建立文档对遇到过的问题进行记录,但是一来麻烦,二来有些当时认为不重要的事情,也许一段时间后认为是重要的,需要记录的,却又一时找不到,浪费时间做重复的事情.正好借着这个机会 ...

  8. destoon 配置文件config.inc.php参数说明

    $CFG['db_host']数据库服务器,可以包括端口号,一般为localhost $CFG['db_user']数据库用户名,一般为root $CFG['db_pass']数据库密码 $CFG[' ...

  9. 【Hadoop/Hive/mapreduce】系列之使用union all 命令之后如何对hive表格使用python进行去重

    业务场景大概是这样的,这里由两个hive表格,tableA 和 tableB, 格式内容都是这样的: uid cate1 cate2 在hive QL中,我们知道union有着自动去重的功能,但是那是 ...

  10. matplotlib学习记录 四

    # 绘制3月每天最高温和10月每天最高温散点图 from matplotlib import pyplot as plt # 让matplotlib能够显示中文 plt.rcParams['font. ...